Note that there are some explanatory texts on larger screens.

plurals
  1. POCodecademy JavaScript Push() Exercise
    primarykey
    data
    text
    <p>The goal is unclear on CodeAcademy. <a href="http://bit.ly/167N8bX" rel="nofollow">http://bit.ly/167N8bX</a> I think am supposed to run through a long string, and push the characters of my name out of the string into an array. </p> <p>Here's how it's stated: </p> <blockquote> <p>"it will check the text for the first letter of your name, then push (add) the number of characters equal to your name's length to an array. By inspecting the array, you'll be able to see if your name was mentioned!"</p> </blockquote> <p>*UPDATED. Now that I see the instructor's output, it doesn't actually check to see if your name is mentioned at all. Confusing instructions for a novice, like me.</p> <p>I am on step 5 of 7: Link: <a href="http://bit.ly/167N8bX" rel="nofollow">http://bit.ly/167N8bX</a></p> <pre><code>var text = "Lorem ipsum dolor nayr sit amet, consectetur adipisicing elit, sed do eiusmod tempor yan ut Ryan labore et dolore magna aliqua. Ut enim ad ry minim veniam, quis nostrud ryan exercitation ullamco ryan laboris nisi ut aliquip ex ea ry commodo rya consequat. END"; var myName = "Ryan"; var hits = []; for(var i = 0; i &lt; text.length; i++) { // Loop thru "text" string // check each char one-by-one // if it finds uppercase "R" if(text[i] == "r".toUpperCase()){ // push the next 3 chars into hits[] array... // by looping on myName.length // end push() when myName.length loops ends for(var j = 0; j &lt; myName.length; j++){ hits.push(text[i]); console.log(hits); } } } </code></pre> <p>*UPDATED How do you keep the output from occurring each loop, and store each push in the array, until after it finishes all the looping? </p> <p>My incorrect output from the above code:</p> <pre><code>[ 'R' ] [ 'R', 'y' ] [ 'R', 'y', 'a' ] [ 'R', 'y', 'a', 'n' ] </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload