get help in general - we have more specialized help rooms here: https://gitter.im/FreeCodeCamp/home
$(document).ready(function(){
var url = 'https://wind-bow.glitch.me/twitch-api/streams/';
var streamers = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"];
for (var x = 0; x < streamers.length; x++) {
$.ajax({
type: "GET",
url: "https://api.twitch.tv/kraken/streams/" + streamers[x],
headers: {
'client-ID': '8wp64ky5gj2bqordmiocrwdw4oivc0'
},
success: function(twitch){
console.log(twitch[x]);
}
}); // End of ajax call.
} // End of x for loop.
}); // End of document function.
x
darrenfj sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
:cookie: 389 | @gersho |http://www.freecodecamp.com/gersho
darrenfj sends brownie points to @just1witness :sparkles: :thumbsup: :sparkles:
:cookie: 315 | @just1witness |http://www.freecodecamp.com/just1witness
darrenfj sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6493 | @manish-giri |http://www.freecodecamp.com/manish-giri
just1witness sends brownie points to @gersho and @dngov :sparkles: :thumbsup: :sparkles:
:cookie: 73 | @dngov |http://www.freecodecamp.com/dngov
:cookie: 390 | @gersho |http://www.freecodecamp.com/gersho
manish-giri sends brownie points to @darrenfj :sparkles: :thumbsup: :sparkles:
:star2: 2004 | @darrenfj |http://www.freecodecamp.com/darrenfj
heroiczero sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6494 | @manish-giri |http://www.freecodecamp.com/manish-giri
manish-giri sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1682 | @heroiczero |http://www.freecodecamp.com/heroiczero
var countEvensAndOdds = function (array) {
var myObj = {};
var evenCount = 0;
var oddCount = 0;
for (var i = 0; i<=array.length; i++) {
if(array[i]%2 === 0) {
myObj.evenCount = evenCount++;
} else {
myObj.oddCount = oddCount++;
}
}
console.log(myObj);
}
console.log(countEvensAndOdds([1,2,3,4,5,6]));
What I am receiving is
[object Object] {
evenCount: 2,
oddCount: 3
}
What I am receiving is
[object Object] {
evenCount: 3,
oddCount: 3
}
for (var i = 0; i < array.length; i++) {
if(array[i]%2 === 0) {
myObj.evenCount = ++evenCount;
} else {
myObj.oddCount = ++oddCount;
}
}
console.log(myObj);
}
manish-giri sends brownie points to @kelechy :sparkles: :thumbsup: :sparkles:
:cookie: 313 | @kelechy |http://www.freecodecamp.com/kelechy
gishy1 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8427 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
(a,b)
in your test. You have to have a < 0 || b < 0
return undefined;
instead of console.log
programnovice sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 545 | @longnt80 |http://www.freecodecamp.com/longnt80
<a href="http://external-page.com">Your text</a>
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "comprepair910@gmail.com";
$email_subject = "The forms";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['full-name']) ||
!isset($_POST['organisation']) ||
!isset($_POST['email']) ||
!isset($_POST['phoneNo']) ||
!isset($_POST['skype'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$fullNames = $_POST["full-name"];
$email = $_POST["email"];
$organisation = $_POST["organisation"];
$facebookId = $_POST["facebook"];
$twitterId = $_POST["twitter"];
$skypeId = $_POST["skype"];
$phoneNumber = $_POST["phoneNo"];
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$fullNames)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(strlen($organisation) < 2) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($fullNames) < 2) {
$error_message .= 'The Names you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($fullNames)."\n";
$email_message .= "Organisation: ".clean_string($organisation)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Telephone: ".clean_string($phoneNumber)."\n";
$email_message .= "Skype: ".clean_string($skypeId)."\n";
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
akodiaemma sends brownie points to @just1witness :sparkles: :thumbsup: :sparkles:
:cookie: 316 | @just1witness |http://www.freecodecamp.com/just1witness
function pairwise(arr, arg) {
var arr1 = [];
var ind = [];
for (var i = 0; i < arr.length; i++){
arr.filter(function(el, index){
if(el + arr[i] === arg){
arr1.push(el , arr[i]);
ind.push(index, i);
arr[index] = "0";
arr[i] = "0";
}
});
}
return ind.reduce(function(sum, value) {
return sum + value;
}, 0);
}
pairwise([1, 3, 2, 4], 4);
pairwise([1, 3, 2, 4], 4);
1+3 = 4
0+1=1 <---
if(el + arr[i] === arg){
to that if, you could add a check that verifies that el and arr[i] aren't one and the same
something like
(el + arr[i] === arg && i !== index)
(assuming i didn't misunderstand your code)
if(el + arr[i] === arg && el !== arr[i])
just1witness sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
:cookie: 391 | @gersho |http://www.freecodecamp.com/gersho
burinson sends brownie points to @longnt80 and @coymeetsworld :sparkles: :thumbsup: :sparkles:
:cookie: 546 | @longnt80 |http://www.freecodecamp.com/longnt80
:star2: 2996 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
$(document).ready(function() {
var streamers = [
"ESL_SC2",
"OgamingSC2",
"cretetion",
"freecodecamp",
"storbeck",
"habathcx",
"RobotCaleb",
"noobs2ninjas"
];
for (var x = 0; x < streamers.length; x++) {
$.ajax({
type: "GET",
url: "https://api.twitch.tv/kraken/streams/" + streamers[x],
headers: {
"client-ID": "8wp64ky5gj2bqordmiocrwdw4oivc0"
},
success: function(twitch) {
console.log(streamers[x]);
if (twitch.stream !== null) {
var logo = twitch.stream.channel.logo;
var name = twitch.stream.channel.display_name;
var status = twitch.stream.channel.status;
var game = twitch.stream.channel.game;
var url = twitch.stream.channel.url;
$("#output").append(
"<a target = '_blank' href=" +
url +
"><div class = 'well'><img id = 'img' src =" +
logo +
">" +
"<br></br>" +
"<p id = 'name'>" +
name +
"</p>" +
"<hr></hr>" +
"<p id = 'game'>" +
game +
"</p>" +
"<p id = 'status'>" +
status +
"</p>" +
"<p id = 'online'>Online</p>" +
"</div></a>"
);
} else {
$("#output").append(
"<div class = 'well-md'>" +
"<img id = 'img' src = 'https://pre06.deviantart.net/1a10/th/pre/f/2015/291/5/1/logo_twitch_iosversion_by_akiruuu-d9djk9s.png'><br></br>" +
"<p id = 'name'>" +
streamers[x] +
"</p>" +
"<p id = 'offline'>Offline</p>" +
"</div>"
);
} // End of else statement.
} // End of success function.
}); // End of ajax call.
} // End of x for loop.
}); // End of document function.
Why is console.log(streamers[x]);
returning undefined and how can I fix it?
"ESL_SC2",
"OgamingSC2",
"cretetion",
"freecodecamp",
"storbeck",
"habathcx",
"RobotCaleb",
"noobs2ninjas"
$(document).ready(function() {
var streamers = [
"ESL_SC2",
"OgamingSC2",
"cretetion",
"freecodecamp",
"storbeck",
"habathcx",
"RobotCaleb",
"noobs2ninjas"
];
for (var x = 0; x < streamers.length; x++) {
$.ajax({
type: "GET",
url: "https://api.twitch.tv/kraken/streams/" + streamers[x],
headers: {
"client-ID": "8wp64ky5gj2bqordmiocrwdw4oivc0"
},
success: function(twitch) {
console.log(streamers[x]);
if (twitch.stream !== null) {
let logo = twitch.stream.channel.logo;
let name = twitch.stream.channel.display_name;
let status = twitch.stream.channel.status;
let game = twitch.stream.channel.game;
let url = twitch.stream.channel.url;
$("#output").append(
"<a target = '_blank' href=" +
url +
"><div class = 'well'><img id = 'img' src =" +
logo +
">" +
"<br></br>" +
"<p id = 'name'>" +
name +
"</p>" +
"<hr></hr>" +
"<p id = 'game'>" +
game +
"</p>" +
"<p id = 'status'>" +
status +
"</p>" +
"<p id = 'online'>Online</p>" +
"</div></a>"
); // End of online append.
} else {
$("#output").append(
"<div class = 'well-md'>" +
"<img id = 'img' src = 'https://pre06.deviantart.net/1a10/th/pre/f/2015/291/5/1/logo_twitch_iosversion_by_akiruuu-d9djk9s.png'><br></br>" +
"<p id = 'name'>" +
streamers[x] +
"</p>" +
"<p id = 'offline'>Offline</p>" +
"</div>"
); // End of offline append.
} // End of else statement.
} // End of success function.
}); // End of ajax call.
} // End of x for loop.
}); // End of document function.
he trying to say use let x = 0?
correct? @ericmiller777
burinson sends brownie points to @ericmiller777 :sparkles: :thumbsup: :sparkles:
:cookie: 278 | @ericmiller777 |http://www.freecodecamp.com/ericmiller777
"VanillaJS is a name to refer to using plain JavaScript without any additional libraries like jQuery. People use it as a joke to remind other developers that many things can be done nowadays without the need for additional JavaScript libraries."
function myReplace(str, before, after) {
str = str.split(" ");
before = before.split("");
after = after.split("");
if(before[0].toUpperCase() == before[0]){
after[0] = after[0].toUpperCase();
}
before.join("");
after.join("");
for(let i = 0; i < str.length; i++){
if(str[i] == before){
str[i] = after;
}
}
return after;
}
myReplace("He is Sleeping on the couch", "Sleeping", "sitting");
return after;
?
before
after = after.join("");
ericmiller777 sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 442 | @korzo |http://www.freecodecamp.com/korzo
unction myReplace(str, before, after) {
str = str.split(" ");
before = before.split("");
after = after.split("");
if(before[0].toUpperCase() == before[0]){
after[0] = after[0].toUpperCase();
}
after = after.join("");
for(let i = 0; i < str.length; i++){
if(str[i] == before){
str[i] = after;
}
}
return str.join(" ");
}
myReplace("He is Sleeping on the couch", "Sleeping", "sitting");
function myReplace(str, before, after) {
str = str.split(" ");
for(let i = 0; i < str.length; i++){
if(str[i] == before){
str[i] = after;
}
}
return str.join(" ");
}
myReplace("He is Sleeping on the couch", "Sleeping", "sitting");
ericmiller777 sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:warning: ericmiller777 already gave korzo points
var str = 'Hello World';
console.log(str[1]);
str.charAt(1)
burinson sends brownie points to @gothamknight :sparkles: :thumbsup: :sparkles:
:cookie: 415 | @gothamknight |http://www.freecodecamp.com/gothamknight
burinson sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
:cookie: 393 | @gersho |http://www.freecodecamp.com/gersho