本文介绍了javascript中的三元opeartor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是jQuery,平台是Visual Code。我是Mean Stack的新手。我正在使用三元运算符来练习。我做了一个程序,但它并没有按我的意愿给我输出。我不确定这个问题。我希望用户输入年龄并通过三元运算符给出输出。当我运行cmd时,它运行程序并打印你的年龄是多少并向我显示 ReferenceError:提示未定义。
谁能告诉我哪里错了?
我尝试了什么:
var name = prompt(' 你的年龄是多少?');
console.log(name);
var 年龄;
var voteable =(age < 18 )? 太年轻了: 足够老;
解决方案
I am using jQuery and platform is Visual Code. And I'm a newbie in Mean Stack. I am using Ternary Operator to practice. I made a program, but it's not giving me the output as I want. I'm not certain about the problem. I want the user to enter the age and give me output as done by the ternary operator. When I run cmd, it runs the program and print 'What's is your age' and shows me ReferenceError: prompt is not defined.
Can anybody tell me where I am wrong?
What I have tried:
var name = prompt('What is your age?'); console.log(name); var age; var voteable = (age < 18) ? "Too young":"Old enough";
解决方案
这篇关于javascript中的三元opeartor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!