简体   繁体   中英

Return value of the JavaScript function

I am doing the online code test. The question is about the javascript function.

Below is a question:

First, answer this code question: This is a javascript function. Please input the response of this function in the field below.

function test(name, birth_year, current_year) {
  const age = current_year - birth_year;
  const response = name + " is " + age;
  return response;
}

test("jane", 1979, 1990)

Enter the return value of the function. jane is 11

This is picture of question: 输出1

When I have submitted the answer is jane is 11 . The system told me the answer is wrong. May I ask what is the actual return value of the function? Because the online system didn't let me know the correct answer. Hope someone can guide me on how to solve it. Thanks.

Im pretty sure the system says its wrong because you didnt put " quotation marks to make it a string data type like "jane is 11"

If its still wrong, its either using single quotation marks ' or the developer wrote it wrong

If you copy and paste the code into the console it literally returns the string: "jane is 11" . Looking at your answer the only thing missing is the quotation marks.

If that is the way you entered the answer it would be wrong. Make sure you answer it as "jane is 11" , (double quotes) 'jane is 11' (single quotes) or `jane is 11` (template literals).

Using quotations or backticks makes sure Javascript interprets it as a string.

正确和最终的答案将使用双引号,即“jane is 11”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM