如何正确回答此练习?我不知道答案应该是什么样

时间:2019-07-20 21:15:13

标签: javascript if-statement

该练习要求多行还是1行?它总是告诉我它的错。我不知道为什么 我曾尝试使用Google搜索,但没有找到对我有意义的任何内容。请帮忙!

df <- data.frame(id = c(1L, 1L, 1L),
                 startDate = c("1990-01-01", "1990-01-23", "1990-01-30"),
                 endDate = c("1990-01-24", "1990-01-25", "1990-01-31"), stringsAsFactors = F)

conti(df)
#[1] "Done in 0 secs. A data.table was produced."
#   id  startDate    endDate
#1:  1 1990-01-01 1990-01-25
#2:  1 1990-01-30 1990-01-31

2 个答案:

答案 0 :(得分:0)

只需添加引号。

function exerciseFour(age){
  let typeOfLicense;
  // In this exercise, you will be given a variable, it will be called:age
  // You are also given another variable called: typeOfLicense;
  // Using an if/else if/else statement assign typeOfLicense to:
  // 'Full License' if age is greater than or equal to 16,
  // 'Permit' if age is equal to 15,
  // 'None' if age is less than 15
if (age >= 16) {
  typeOfLicense = 'Full License';
} 
else if (age === 15) {
  typeOfLicense = 'Permit';
} 
else {
  typeOfLicense = 'None';
} 

答案 1 :(得分:0)

实际的代码问题已在上面解决。

但是您需要学习和理解的是Java语言中的字符串。

代码中有一些错误,当您尝试使用不带引号的Permit时,Javascript会假定您正在尝试使用变量名,但是当然该变量不存在。

代码中的另一个错误,当您尝试使用不带引号的Full License时,Javascript无法锻炼代码内容,并且会抛出语法错误,称unexpected identifier。您不能将两个变量(标识符)并排放置,这就是Javascript认为您要尝试做的事情。

为充分理解字符串,本文值得研究: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Strings

相关问题