Codecademy howOld语法错误,否则

Dar*_*der 0 javascript syntax if-statement

作为编码新手,我总是在Codecademy的Javascript练习中苦苦学习语法。这是我在没有互联网搜索帮助的情况下无法解决的第一个问题-如果在此已经解决,我深表歉意。

I am usually a semi-colon away from solving it, but not this time (?). Im attempting to accommodate 3 outcomes:

  1. someone inputs a year in the future and I tell them their age in that year.

  2. someone inputs a year before they were born and I give them the # of years until they were born.

  3. someone inputs a year after they were born and I give them their age at that time.

I've spent too much time moving curly brackets and semi colons and I guess I just cant see the error.

const howOld = (age, year) =>

 {
  if 
    (year > 2019);
    let calculatedAge = ( year - 2019 + age );
  {
  return `You will be ${calculatedAge } in the year ${year}.`;

  } else if 
    (year < (2019-age));
    let calculatedAge = ( 2019 - year + age ); 
  {
  return `The year ${year } was ${calculatedAge } years before you were 
born.`;

  } else 
    let calculatedAge = ( year - 2019 + age );
  { 
  return `You were ${calculatedAge} in the year ${year}. `; 
  }

};

console.log(howOld(47,2000))
Run Code Online (Sandbox Code Playgroud)

I am getting a syntax error at my 'else if' statement.

Jav*_*cke 6

这应该做

    const howOld = (age, year) =>

 {
  if(year > 2019)
  {
    let calculatedAge = ( year - 2019 + age );
    return `You will be ${calculatedAge } in the year ${year}.`;

  } 
  else if(year < (2019-age))
  {  
    let calculatedAge = ( 2019 - year + age ); 
    return `The year ${year } was ${calculatedAge } years before you were born.`;
  } 
  else
  {
    let calculatedAge = ( year - 2019 + age ); 
    return `You were ${calculatedAge} in the year ${year}. `; 
  }

};

console.log(howOld(47,2000))
Run Code Online (Sandbox Code Playgroud)

为了解释您的错误,您使用了if语句错误,而不是

if(condition){do}
Run Code Online (Sandbox Code Playgroud)

你有过

if(condition);do{do}
Run Code Online (Sandbox Code Playgroud)