I am trying to create an online lottery system in which user has to guess a number between 1 to 10. If the number matches with the javascript generate random number he will win the lottery. The method I used is:
!function(){ var x = Math.floor((Math.random() * 10)); var btn = document.getElementById("btn"); btn.addEventListener("click", function(){ var user_input = document.getElementById("text").value; if( user_input == x) { alert("Won Lottery", user_input, x); } else { alert(user_input + x + "sorry"); } }); }();
<h2>Guess a number between 1 and 10 </h2> <input id="text" type="text"> <button id="btn" type="submit">Submit</button>
My question is, can a hacker open the js console and somehow find the value of local x
variable?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.