javascript中的三元opeartor [英] Ternary opeartor in javascript
问题描述
我使用的是jQuery,平台是Visual Code。我是Mean Stack的新手。我正在使用三元运算符来练习。我做了一个程序,但它并没有按我的意愿给我输出。我不确定这个问题。我希望用户输入年龄并通过三元运算符给出输出。当我运行cmd时,它运行程序并打印你的年龄是多少并向我显示 ReferenceError:提示未定义。
谁能告诉我哪里错了?
我尝试了什么:
var name = prompt(' 你的年龄是多少?');
console.log(name);
var 年龄;
var voteable =(age < 18 )? 太年轻了: 足够老;
试试这个
var age = prompt(' 你的年龄是多少?');
var voteable =(age < 18 )? 太年轻了: 够老;
alert(可投票);
您尚未将提示
中的值分配给年龄变量。
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";
try this
var age = prompt('What is your age?'); var voteable = (age < 18) ? "Too young" : "Old enough"; alert(voteable);
you have not assigned the value fromprompt
to age variable.
这篇关于javascript中的三元opeartor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!