Learn Basic JavaScript by Building a Role Playing Game - Step 165

Tell us what’s happening:

Hello. There is a failure in my code because it isn’t passing. Please help me find out what is wrong.

function pick(guess) {
    const numbers = [];
    
    
    while (numbers.length < 10) {
        numbers.push(Math.floor(Math.random() * 11));
    }

    
    document.getElementById('text').innerText = "You picked " + guess + ". Here are the random numbers:";
}

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

function pick(guess) {
    const numbers = [];
    
    
    while (numbers.length < 10) {
        numbers.push(Math.floor(Math.random() * 11));
    }

    
    document.getElementById('text').innerText = "You picked " + guess + ". Here are the random numbers:";
}

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 OPR/114.0.0.0

Challenge Information:

Learn Basic JavaScript by Building a Role Playing Game - Step 165

Hi there!

The instructions didn’t asked to add getElementId method.

In accordance with the instructions, I removed the getElementId method. But the problem still exists . Here it is:

function pick(guess) {
    const numbers = [];
    
    while (numbers.length < 10) {
        numbers.push(Math.floor(Math.random() * 11));
    }

   
    console.log("You picked " + guess + ". Here are the random numbers:");
    console.log(numbers);
}

@Dennis-code153

Did the instructions asked to add the value to the console.log() ?
Edit: After the while loop, set text.innerText to equal "You picked <someGuess>. Here are the random numbers:". Replace <someGuess> with the guess function parameter.

You mean this one:

text.innerText = "You picked " + guess + “. Here are the random numbers:”;

Exactly, but don’t copy the above one to the challenge editor. It’s last two double quote marks are altered by you here mistakenly. You can see half the string is showing red and half is white. Use the straight " quote marks for insure to pass the challenge.

1 Like

Thank you very much. I did everything as you said and it helped me to cope with the test. I really appreciate your invaluable help in the form of advice. With your help, I finally completed the entire project.


1 Like

You have not started talking about your code as you have promised. You again wrote something like “it doesn’t work, tell me what’s wrong”

1 Like

You write: "You still haven’t started talking about your code, as promised. You wrote something like “it’s not working, tell me what’s wrong.” Yes, I tried my best to learn how to talk about my code, about its length, about the developer console and other problems related to my code, but unfortunately I haven’t managed to learn how to talk about it yet, since I finished the project a long time ago.


You can start including these:

  1. Any error messages you get - Post these in their entirety. Look in both the terminal and web console for errors. Screenshots are OK if they have the whole error message, but text is better.
  2. A description of the issue, answering each of the following questions - Be as detailed as possible. Include screenshots of the actual (and, if possible, expected) behaviour if you can.
    a) What exact steps did you take to make the issue happen?
    b) What was the expected result?
    c) What was the actual behaviour?
1 Like

Thank you. I’ll be trying to do it.