javascript - How to get math.random to work? -
i wrote code math.random make random number between 1 3 when press click me button, give +3 doesn't random between 1 3.
i want give between 1 3 when click button.
var cookies = 0; var rand = math.floor(math.random() * (3 - 1 + 1)) + 1; if(localstorage.cookies) cookies = localstorage.getitem('cookies'); document.getelementbyid("cookies").innerhtml = cookies; function cookieclick(number) { cookies = parseint(cookies) + rand; document.getelementbyid("cookies").innerhtml = cookies; localstorage.setitem('cookies', cookies); }
generate random number each time button clicked, not @ top of script. also, why subtracting 1 3 adding right back?:
function cookieclick(number){ var rand = math.floor(math.random() * 3) + 1; cookies = parseint(cookies) + rand; document.getelementbyid("cookies").innerhtml = cookies; localstorage.setitem('cookies', cookies); }
Comments
Post a Comment