Code not working for 12?


#1

var names = ["Amanda", "Bob", "Charlie", "Danny", "Emma"];

for (var i = 0; i < names.length ; i ++); {
console.log = ("I know someone called " + names[i]);
Could someone tell me what is wrong with this code please. I prints 'I know someone called undefined' when I save and submit it!!!! PLEASE HELP


#2

Delete that "=" operator after log and before your parentheses.


#3

I tried that and it says syntax error! :frowning:


#4

By using the = operator you've overwritten the console.log function so to reset this you need to refresh the page. Also no semicolon after the for loop otherwise it will confuse the
semicolon with the function body. Meaning it will not loop over the
stuff in {} but just do nothing while counting up, as the semicolon
means /*do nothign -> statement-end-sign*/;


#5

I cannot see the problem in my syntax - can someone help? When I submit code, it says unexpected token [

var names ["laura", "danny", "julia", "jo", "eri"];
for (var i = 0; i > names.length; i++) {
console.log("I know someone called "+ names);
}


#7

var names = ["laura", "danny", "julia", "jo", "eri"];
          ^

Don't forget that variables need assignment operators. (such as "=") so it knows what it's suppose to be.


#8

I've tried this code and get an error:

// Click on "Stuck? Get a hint!" if you get stuck!

var names = ["Anya", "Angela", "Haylie", "Howard", "Luci"];

for (var i = 0; i < 5; i++) {
    console.log("I know someone called ", names[i]);
}

If I delete the space at the end of the string that is the first parameter to console.log, the error goes away.


#9

with

for (var i = 0; i < 5; i++) {

try instead:

for (var i = 0; i < names.length; i++) { /*Not solution, but it will mean you don't have
to change the for loop any time you change the array. */

and

console.log("I know someone called ", names[i]); //Problem!

should be:

console.log("I know someone called " + names[i]); //Solution!
                                     ^

#10

hi your problem is in the for loop its printing out and extra array that it doesnt have ... the reason its doing this is cause your telling it to print out i until i <= names.length ... so it will print out and extra one since the array data positions start at 0 .. u need to delete the = ....
second is the console.log doesnt need the =
third you do need a space in between "i know someone called"+ names[i] if you dont add and emty space then the sentence will print out the the names and i know someone calledamanda to add the extra space modify code to include it example
console.log ("I know someone called " +" " + names[i]); hope you can see the extra space add it lol


#11
 console.log("I know someone called ", names[i]);

Well using a comma in a console.log is like using a second paramter, that is ok and the parameters are seperated by a space so that's why you don't need an extra space here. But as this is not introduced in the course I guess it's rather advertised to add a space manualy.


#14

2 posts were split to a new topic: Sorry folks, but could any one spot what I'm doing wrong here?


#15