Click here to Skip to main content
15,902,777 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:

C#
var name = prompt('What is your age?');
console.log(name);
var age;
var voteable = (age < 18) ? "Too young":"Old enough";
Posted
Updated 29-May-16 1:35am
v3

1 solution

try this

C#
var age = prompt('What is your age?');
       var voteable = (age < 18) ? "Too young" : "Old enough";
       alert(voteable);

you have not assigned the value from prompt to age variable.
 
Share this answer
 
v2
Comments
wardakhan 29-May-16 7:19am    
I got an error on (age < 18):
[ts] Operator '<' cannot be applied to types 'string' and 'number'.
var age: string
Karthik_Mahalingam 29-May-16 7:21am    
try parsing.
javascipt or some other lang?

var age = prompt('What is your age?');
age = parseInt(age);
var voteable = (age < 18) ? "Too young" : "Old enough";
alert(voteable);
wardakhan 29-May-16 7:26am    
Same error. Well, I'm learning Mean Stack.
Karthik_Mahalingam 29-May-16 7:33am    
ok. I am not aware of Mean Stack.
the code which i have posted is for pure javascript.
you can just try that code in the console window of your web browser...
Could you please improve the question with the exact need and the Language/Tools/Framework you are working on it. so it will be easy for us to provide the solution .
wardakhan 29-May-16 7:36am    
Yeah, I've updated.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900