+ 2

Can I use Conditional Statement like If and Else in Function like -

function age(a){ if(age>=18){ console.log("You can Drink") } else{ console.log("You cannot Drink") } return b; }

20th Feb 2022, 6:35 AM
Ankur Jha
Ankur Jha - avatar
2 Antworten
+ 5
You can also use ternary operator Its easy & short too console.log(age>=18?"you can drink " : "you cannot drink" ) but what is "b" ? on the last line `` return b; ``
20th Feb 2022, 7:36 AM
Pariket Thakur
Pariket Thakur - avatar
+ 1
Pariket Thakur Actually, I'm a Beginner of Javascript, typing b is my mistake, I Don't know what is that😅
20th Feb 2022, 7:40 AM
Ankur Jha
Ankur Jha - avatar