Search code examples
javascriptobjectif-statementfor-in-loop

Trying to use for...in loop and adding an if/else statement and keeps saying i am missing a ")"


const testScores = {
  John : 99,
  Jess : 78,
  Ryan : 89,
  Tom : 62,
  Jane: 57,
  Ben: 83
};

for (person in testScores){
  
       if (testScores[person] > 90){
       console.log("Well done "+ person ". You scored " + testScores[person])
  };

       else{
       console.log(person + " scored " + testScores[person])};
}

Solution

    • First is typo, you forgot to add the + between person and ". You scored "
    • Second you are using ; after if block, because of that, it program didn't compile.

    const testScores = {
      John: 99,
      Jess: 78,
      Ryan: 89,
      Tom: 62,
      Jane: 57,
      Ben: 83
    };
    
    for (person in testScores) {
      if (testScores[person] > 90) {
        console.log("Well done " + person + ". You scored " + testScores[person]);
      } else {
        console.log(person + " scored " + testScores[person]);
      }
    }