[英]JavaScript simple if statement - print yes
if (2<3), console.log (yes)
this does not work. 这行不通。 How can I fix this?
我怎样才能解决这个问题? i want to print "yes" if this is true if not console.log, what this should be?
如果不是console.log,我想打印“是”,这应该是什么?
There are a few errors with your code: 您的代码有一些错误:
,
because it is invalid syntax. ,
因为它是无效的语法。 You code should look like this: 您的代码应如下所示:
if (2<3) console.log ('yes')
Then you should see 'yes' printed in your console. 然后,您应该在控制台中看到“是”的字样。
As others have stated, this is due to syntax problems. 正如其他人所说,这是由于语法问题。 There shouldn't be a comma, and the yes should be 'yes' or "yes".
不应使用逗号,并且应为“是”或“是”。
if (2<3) console.log ('yes');
OR 要么
if (2<3) console.log ("yes");
should work how you want it to. 应该按照您想要的方式工作。 JavaScript does not know that you are trying to output a string.
JavaScript不知道您正在尝试输出字符串。 What you are doing in the code you provided is actually trying to print out a variable that is named yes.
您在提供的代码中所做的实际上是尝试打印出一个名为yes的变量。 If you would like to print out a variable named yes, it would be something along the lines of
如果您想打印出一个名为yes的变量,那将是类似于
var yes = "yes";
if(2<3) console.log(yes);
Be very careful of syntax! 注意语法!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.