freecodecamp.cn icon indicating copy to clipboard operation
freecodecamp.cn copied to clipboard

why my code aways say error!

Open ttpod123 opened this issue 9 years ago • 4 comments

Challenge Golf Code has an issue. User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36. Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:

function golfScore(par, strokes) {
  // Only change code below this line
  if(strokes=1){
    return "Hole-in-one!";
  }else if(strokes <= par-2){
    return "Eagle";
  }
  else{
  return "Change Me";
  }
  // Only change code above this line
}

// Change these values to test
golfScore(5, 4);

ttpod123 avatar Mar 30 '17 07:03 ttpod123

@ttpod123

  1. You need to use === instead of = for comparison. The equal sign is used for assignment.
  2. You are supposed to handle all other cases like "Birdie", "Par", etc.

S1ngS1ng avatar Mar 30 '17 17:03 S1ngS1ng

function golfScore(par, strokes) { // 请只修改这条注释以下的代码 if (strokes==1){ return "Hole-in-one!"; } else if(strokes==par-1) { return "Birdie"; } else if(strokes==par){ return "Par"; } else if(strokes==par+1){ return "Bogey"; } else if(strokes==par+2){ return "Double Bogey"; } else if(strokes>=par+3){ return "Go Home!"; }

else{ return "Eagle"; }

// 请只修改这条注释以上的代码 }

isscal avatar Jun 21 '17 02:06 isscal

注意:在这里的“=”是赋值的意思,而“==”才是相等的意思。

RillHe avatar Jan 23 '18 14:01 RillHe

只看出来是赋值“=”和“==”的问题。

Wanlin-Lu avatar Jan 23 '18 15:01 Wanlin-Lu