0

let a = prompt('Enter 1st number');
console.log(a);
let b = prompt('Enter 2nd number');
console.log(b);
let msg = (a + b < 4)?'Below':'Over';
console.log(msg);

Following code Outputs :

Case 1 : a=0, b=1, msg='Below' Case 2 : a=1, b=1, msg='Over'

Case 2 answer should be 'Below;, Where am I wrong ?

Turnip
  • 35,836
  • 15
  • 89
  • 111
  • As a shortcut you can use `let a = +prompt('Enter 1st number');` to convert the returned string to a number on the spot. –  Nov 20 '19 at 12:15
  • 1
    You can use as `parseInt(a) + parseInt(b)` for converting string to int – Ahmet Amasyalı Nov 20 '19 at 12:16
  • @AhmetAmasyalı I just got the answer and in my solution I am using Number() to convert them into number datatype : let a = Number(prompt('Enter 1st number')); console.log(a); let b = Number(prompt('Enter 2nd number')); console.log(b); let msg = ( a + b < 4)?'Below':'Over'; alert(msg); – Gitanshu Choudhary Nov 20 '19 at 12:37

0 Answers0