FizzBuzz exercise

I’ve been having trouble solving this exercise for 2 days now, i went back and watched java script for beginners by the channel the academy recommended, from reeducating myself in parts i didnt fully understand and going over through parts of the eloquent book that i felt were important to solving this, oh and also Google i arrived to what i feel like 80% completion with 20% still missing, i am slightly frustrated so im asking for help on the 20% i dont need the answer just a clue or recommendation that will lead me to it.

this is my code:

for (let i = 1; i <=100; i++){console.log(i);
if (i%3) {
console.log (“fizz”)
}
while (i%5) {console.log(“buzz”);
if (“i%3”+“i%5”) { console.log(“fizzbuzz”)

  }
  break}
}

Hello @EricAlmonte, hope you are ok.

You have issues with your IF statements, you are using IF (i%3), thats an operation, but what about the result? an If should be used to get a valid value like (i%3 == 0) mean: i modulus at 3 must be equal to zero, that case the IF will be TRUE, but your conditional statements (if) are not correctly designed.

Here is a quick example on the same assignment:

<!DOCTYPE html>

<html>
	
	<head>
	<meta charset="utf-8">
		<title></title>
		
		<script>
			for (i = 1; i <= 100; i++) {
				if (i % 3 == 0 && i % 5 == 0) {
					console.log("FizzBuzz");
				} else if (i % 3 == 0) {
					console.log("Fizz");
				} else if (i % 5 == 0) {
					console.log("Buzz");
				} else {
					console.log(i);
				}
			}
		
		</script>
	</head>
	
	<body>
		
	
	</body>
	
</html>

Hope you find this useful.
If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

3 Likes

Thank you for your help i really appreciate it! i was stuck and ready to give in lol. Sometimes i feel like im supposed to get it right away but everyone keeps telling me it takes a good 3-6 months to really feel comfortable. Anyway Thanks for the help again.

2 Likes