I can't seem to make this work - it always gives the result of time = 1 even if another time value is generated?
function myFunction() {
var time = Math.floor((Math.random() * 3) + 1);
document.write(time + " ");
var greeting;
if (time = 1) {
greeting = location.replace("https://x1.com.html");
} else if (time = 2) {
greeting = window.location.replace("https://x2..html");
} else {
greeting = ("https://x3.com.html");
}
}
<body>
<p>Click the button to continue</p> <button onclick="myFunction()">Try it</button>
<p id="demo"></p>
</body>
Aucun commentaire:
Enregistrer un commentaire