Why code isn't working?

Hey, I’m trying to figure out a simple program for guessing a number from 0 to 100. The user should have only 5 attempts. If I have missed something, please let me know.
Here is the code:

let random = parseInt(Math.random() * 100); 

let out = document.getElementById("message");

let counter = 0;

let userNum;

do {

    userNum = prompt("Guess the number (between 0-100)");

        if(userNum === null){ 

        out.innerHTML = "Cancel!! That is Okay. You can play another time";

        break; 
    }

    userNum = parseInt(userNum);

    if (userNum === random) {

        out.innerHTML = "Congratulations. ";

        //  break; 

    } else {

         out.innerHTML = "That was not the right number. Try again! ";

        alert("That was not the right number!");

    }

    counter++;  

}while(counter < 5 && userNum !== random); 

if(counter == 5 && userNum !== random){

    out.innerHTML = `You ran out of chances!! The number was ${random} . Try again later`;

This code is working perfectly fine for me. I don’t understand the exactly problem you are facing can you pleaes elaborate?

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

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