javascript - 我怎么没有正确使用分号(javascript)?

标签 javascript syntax

我正在学习 Udacity 的 JS 入门类(class),我对这个关于分号的教程感到困惑!

问题是:

Directions: Define two variables called thingOne and thingTwo and assign them values. Print the values of both variables in one console.log statement using concatenation. For example,

red blue

where "red" is the value of thingOne and "blue" is the value of thingTwo. Don't forget to use semicolons!

我几乎尝试了所有的变体,但我总是得到错误的答案。我收到此消息:

What Went Well

  • Your code should have a variable thingOne

  • Your code should have a variable thingTwo

  • Your code should only have one console.log statement

  • Your code should print out the values of thingOne and thingTwo using concatenation

What Went Wrong

  • Your code is missing semicolons at the end of each line

这是我的回答:

var thingOne = "red";
var thingTwo = " blue";
console.log(thingOne + thingTwo);

我也尝试过:

var thingOne = "red"; var thingTwo = " blue";
console.log(thingOne + thingTwo);

我还尝试了这两种组合,其中 console.log 语句末尾没有分号...只是为了看看这是否是问题所在。

这些都没有通过测试。

这是他们的错误还是我遗漏了什么? 很抱歉问了这个极其简单的问题。我只是想确保我正确地学习 JS。谢谢

最佳答案

您的解决方案是这样的:

var thingOne = "red";
var thingTwo = "blue";
console.log (thingOne + " " + thingTwo);

https://repl.it/@meghann/Programming-Quiz-Semicolons-2-8

关于javascript - 我怎么没有正确使用分号(javascript)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55764593/

相关文章:

javascript onclick自定义光标

JavaScript 正则表达式和捕获组

java - 出于语法原因,是否值得使用长度为 2 的数组而不是两个变量?

c# - 三元运算符;这个语法有什么问题?

php - PHP中的双下划线

haskell - lambda 表达式中分号的含义

javascript - .animate 不重复 .toggle 点击事件

javascript - AJAX jQuery 无法识别我的表单

javascript - 使用 javascript 或 momentjs 仅将 UTC 时间转换为本地时间(无日期)

syntax - 一行上有多个本地人?