I wanted the user to input a number and if the number is a multiple of 3 or 5, I want a word/paragraph that says, "You are a witch"
created a function but I cannot seem to make it work
var x;
function pop(){
for (x=1; x <= 100; x++)
if (x % 3 == 0 ) {
document.getElementById('onClick').innerHTML = "You are a Warrior";
}else if (x % 5 == 0){
document.getElementById('onClick').innerHTML = "You are a wizard";
}else if (x % 3 == 0 && x % 5 == 0) {
document.getElementById('onClick').innerHTML = "You are a Sage";
}else {
document.getElementById('onClick').innerHTML = "invalid";
}
}
<input type="number" id="x">
<br>
<br>
<center><button onclick="pop()">Click Me</button> </center>
<br>
<br>
<p id="onClick"></p>
Aucun commentaire:
Enregistrer un commentaire