Unexpected token error in my JavaScript code


#1

Can you please check my code below to see how I can solve the “Unexpected token error”:

let num = 0;
	if ( num <= 100 ){
		console.log(num);
		num = num + 1;
	} else if (num % 3 === 0) {
		console.log(newnum);
		newnum = "fizz";
	} else if (num % 5 === 0) {
		console.log(newnum);
		newnum = "buzz";
	} else (num % 15 === 0) {
		console.log(newnum);
		newnum = "fuzzbizz";	
	}

#2

I see multiple mistakes, but the one giving you an error at the moment is that else can’t have a condition, since else is everything else.


#3

Thanks for spotting the error, I’m a newbie and I’m learning alone so, you know, it’s kinda hard.


#4

Hey, can you help a little bit?


#5

with what?


#6

You see, the “fizz” and the “buzz” should be instead of 3 and 5 but it doesn’t replace them in this code:

let num = 1;
	while (num <= 100){
		console.log(num);
		num = num + 1;
	if ( num % 3 == 0) {
		console.log("fizz");
	} else if (num % 5 == 0) {
		console.log("buzz");

	} 
}

#7

if you want this, think about the order of your conditions. What should come first?


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.