this is my first post here. Im a newbie learning javascript. Im stuck on a problem for my coding homework. here it is:
// Write a loop that logs "Marco!" when i is even,
// "Polo!" when i is odd.
// Do not edit the existing code.
// Hint 1: Use an if/else statement
// Hint 2: Google the mod operator (%)
// my attempt
let x=11;
let y=4;
let i=x%y;
if (i) {
console.log("Marco!")
}
else {
console.log("Polo")
}
this logs marco when i need it to log polo. Im stuck and frustrated, so while I continue to try and solve this I wanted to see how experts would do it.
thanks for your help!
Aucun commentaire:
Enregistrer un commentaire