Curious on question 7. Victory!


#1

Does anyone know how we can fix the situation mentioned in that paragraph: if it print out all the letters just according to the first letter of name. How to add more conditions so it matches the letters from the name?


#2

@xiao89,
Instead of pushing each character found in your Second-FOR-loop,
you will have to collect these characters into a temporary variable using the concatenation.

AFTER leaving the Second-FOR-loop
( all characters have been collected in a temporary variable )
In an IF condition you compare myName with tempVar ( myName === tempVar )
and if true, you can than push myName into the hits-Array.


#3

Thank you! It's very clear and helpful.


#4

@xiao89:
an alternative to concatenation is to use the javascript join() method.

so if have an array:
var arr = ["J", "a", "n", "e"];

you can join the elements to create a string "Jane" by typing:

arr.join("");

As an aside, the "" argument means there will be no spaces in between the joined elements; that is, an argument of "," would create a string:
"J,a,n,e"

Hope this helps.


Victory! (Name Search+) Array Organization Question
Question 7 Attempts With Separate Array But Returns Error
#5

Can you explain this in more detail? I'm not sure what you mean by "( all characters have been collected in a temporary variable )". How do I collect all characters into the tempVar variable?


#6

@webcoder09707,

I believe "second temporary variable" is referring to a variable that is assigned to an array. In other words, a second array. Does that help?

frisby