Question


#1


1. Populate the "people" array with 7 names (strings) using the push method. Please makes some names short, and some names long.
2. Write a function called "greetNamesLongerThanX".
This function takes an array of names (strings) AND a number X. It should return the following string "Hello, , , , ...etc..., how are you all doing?", but it will only greet people who's names are longer than X characters.


Hello, The question is not related to Code academy course. Can you please still help me out ? I keep getting this Error message.

"TypeError: arrayOfNames.length is not a function"

Thanks !!


var people = [ ];
people.push("sara","michelle","vincent","jina","francois","pyojin","hyunjin");

function greetNamesLongerThanX(arrayOfNames, numberX) {
for(var i=0; i<arrayOfNames.length; i++){
var temp = "";
if(arrayOfNames.length() > numberX){ 
temp = temp + "<" + arrayOfNames[i] + ">";
console.log("Hello,"+ temp+ ",...etc..., how are you all doing?");
} else {return temp};  
};
} 
console.log(greetNamesLongerThanX(people, 6));


#2

It should be..
arrayOfNames.length
In JavaScript It's(length) a property not a function.

Array Length - MDN


#3

"Hello,,...etc..., how are you all doing?"
"Hello,,...etc..., how are you all doing?"
"Hello,,...etc..., how are you all doing?"
"Hello,,...etc..., how are you all doing?"
"Hello,,...etc..., how are you all doing?"
"Hello,,...etc..., how are you all doing?"
"Hello,,...etc..., how are you all doing?"

It print out this above instead of

"Hello,,,,,...etc..., how are you all doing?"


#4

hi , your people array have 7 elements that's why it printed 7 times


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.