Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Number prediction from 1 to 10 from javascript

This is my code but when i run this code in console always giving me Congratulations.
Help me for solve this problem.

var val=Math.floor(Math.random() * 10) + 1;
console.log(val);
var Predict = Number(prompt("Prediction ?"));

for(var i=1 ; i <= 3; i++){
  if(Predict<val){console.log("Up")};
  if(Predict=val){console.log("Congratulations") };
  if(Predict>val){console.log("Down")}
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Equal operator assigns the right hand to the left hand and so the result is always true! To compare two values use double equals like this:

if (Predict==val){console.log("Congratulations") };
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading