# Generating numbers between 1- 6

Generating numbers between 1- 6
0

#1

Hi I am new to javascript, can you guys help me with the code . Here is the question
Write Javascript code that does the following :

A) Generates a random number in the range of 1 to 6 then store it within a variable.
B) The program should prompt the user to enter a number from in the range of 1 to 6.q
C) If the number entered by the user does not match the number generated in point A
display a message inside the browser to encourage the user try one more time.
Otherwise congratulate the user.

PS: Below is an example on how to prompt the user for input

Here is my code below:

``````<html>
<title>Brief 2 _Question 3 </title>
<body>
<script>
var generate1 = Math.floor(Math.random() * 7);

var ask_user = prompt("Enter the number between 1-6");

var message = alert("Try one more time");
}else

}

</script>
</body>
</html>
``````

#2

I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (`</>`) will also add backticks around text.

#3

First of all, need to check your math. You are using

``````Math.floor(Math.random() * 7)
``````

Because `Math.random()` will return a number between 0 and .99999999999, your formula will return a number between 0 and 6.9999999999. When that gets rounded down, it will give a number from 0-6.

I don’t want to give it away, but hopefully that will point you in the right direction.

As to your loop, I think you need to have the `prompt` inside the loop, so you can keep checking. Maybe use a `do/while` loop so you can check after if there was a match.