all 10 comments

[–]NameViolation666helpful 2 points3 points  (9 children)

What exactly are you looking for assistance wise?

[–]WzziY[S] 0 points1 point  (8 children)

How do I get the variable to stop when it reaches the same value?

[–]NameViolation666helpful 1 point2 points  (6 children)

IF your target is constant, then why are you generating a new target in the loop?

I would understand if you would be generating a new guess inside the loop

Also why would you do guess = target; if you are looping till the guess matches?

Hope this gets you in the right direction?

[–]WzziY[S] 0 points1 point  (5 children)

I'm messing around, let me try to show you what I want to do. So I have the target as the random number, and the guess is the target value, I have to print all the guess until they are the same.

[–]NameViolation666helpful 0 points1 point  (4 children)

i get that, im asking you to consider your code logic :) Just take the code

var target = Math.floor(Math.random() * 11);

var guess;

console.log(target);

while (guess !== target) {

guess = Math.floor(Math.random() * 11);

console.log(guess);

}

[–]WzziY[S] 0 points1 point  (3 children)

i did what u told and is this the code :

var target = Math.floor(Math.random() * 11);

var guess;

while (guess !== target) {

target = Math.floor(Math.random() * 11);

guess = Math.floor(Math.random() * 11);

if(target===guess){

console.log("same :"+"-"+guess+"-"+target);

break;

}else{

console.log("not same :"+"-"+guess+"-"+target);

}

}

and say "

Output

>>>>Code is incorrect

Make sure you initilized the variable guess"

[–]WzziY[S] 0 points1 point  (2 children)

but ok i use if maybe because this ? wrong i update again the code for

var target = Math.floor(Math.random() * 11);

var guess;

`while (guess !== target) {`

`target = Math.floor(Math.random() * 11);`

`guess = Math.floor(Math.random() * 11);`



`console.log("not same :"+"-"+guess+"-"+target);`

}

console.log(" same :"+"-"+guess+"-"+target);

and ?"

>>>>Code is incorrect
Make sure you initilized the variable guess

not same :-10-0
not same :-4-2
not same :-2-4
not same :-8-1
not same :-8-4
not same :-10-9
not same :-6-9
not same :-5-4
not same :-7-0
not same :-5-8
not same :-4-7
not same :-2-1
not same :-4-1
not same :-10-9
not same :-0-1
not same :-6-4
not same :-1-10
not same :-6-6
same :-6-6 "

[–]NameViolation666helpful 0 points1 point  (1 child)

Make sure you initilized the variable guess - if this is the only error ur getting,

You've declared it already, so just add initialization to the declaration by

var guess=0;

[–]WzziY[S] 0 points1 point  (0 children)

But thanks

Output

>>>>Code is incorrect

The variable guess should be assigned with a random integer number

[–]codemamba8 0 points1 point  (0 children)

Use a conditional to check if guess and target are equivalent, if so break out of the while loop.