Help out a newb plz

I have been working my way through udacity prep, and I am having some setbacks. I’ve decided to review some of the past information I have learned which has lead me to posting this question.

here are the instructions

Write a while loop that:

  • Loop through the numbers 1 to 20
  • If the number is divisible by 3, print "Julia"
  • If the number is divisible by 5, print "James"
  • If the number is divisible by 3 and 5, print "JuliaJames"
  • If the number is not divisible by 3 or 5, print the number

here is my code –


while (x <= 20) {
    if(x % 3 === 0) {
        console.log("Julia");
        ++x;
   } else if(x % 5 === 0) {
        console.log("James");
        ++x;
   } else if((x % 3 === 0) && (x % 5 === 0)); {
        console.log("JuliaJames");
        ++x;
   
   } else {
       console.log(x);
   }} ```

Basically, it's telling me that it's expecting an identifier before the } else { statement. I don't understand what I am doing wrong and how it is any different than this code... 


```var runner = "Kendyll";
var position = 2;
var medal;

if(position === 1) {
  medal = "gold";
} else if(position === 2) {
  medal = "silver";
} else if(position === 3) {
  medal = "bronze";
} else {
  medal = "pat on the back";
}

console.log(runner + " received a " + medal + " medal.");

Your else if statement condition shouldn’t have a semicolon after the round parenthesis, that is your unexpected character

Your else statement doesn’t increase x so you will find yourself with a infinite loop

Also, your condition for x divisible by both 5 and 3 it will not run as one of the first two will be executed, and the code blocks in an if/else chain are mutually exclusive

2 Likes

it’s the small things in life.

thank you kindly.

1 Like