10-18-17, 10:46 PM
Heres one that I solved beforeAlso answer to the ? I wrote)
var i;
var myNumber;
myNumber = prompt("Give me your number");
for (i=1; i<=myNumber; i++) {
if (i % 3===0 && i % 5 ===0) {
console.log("FizzBuzz");
}
//if the number is divisible by 3, write "Fizz"
else if (i % 3 === 0) {
console.log("Fizz");
}
//if the number is divisible by 5, write "Buzz"
else if (i % 5 === 0){
console.log ("Buzz");
}
//Otherwise, just write the number
else {
console.log(i);
}
}
(And before you accuse its a copy paste, No, its not on a webpage or forum and no my search history doesnt even have "Fizzbuzz copy paste" in it. I genuinely wrote and spent time on that to answer something as a challenge)
Code:
//initialise variables
var i;
var myNumber;
Code:
//Ask the user for a number
myNumber = prompt("Give me your number");
Code:
// for the numbers 1 through to the number given,
for (i=1; i<=myNumber; i++) {
Code:
//test the number for being divisable by BOTH 3 & 5
if (i % 3===0 && i % 5 ===0) {
console.log("FizzBuzz");
}
//if the number is divisible by 3, write "Fizz"
else if (i % 3 === 0) {
console.log("Fizz");
}
//if the number is divisible by 5, write "Buzz"
else if (i % 5 === 0){
console.log ("Buzz");
}
//Otherwise, just write the number
else {
console.log(i);
}
}
(And before you accuse its a copy paste, No, its not on a webpage or forum and no my search history doesnt even have "Fizzbuzz copy paste" in it. I genuinely wrote and spent time on that to answer something as a challenge)