0
Tip Converter
Why is my output coming out as NaN, and why does it not add up my tip + bill and tip https://code.sololearn.com/Wehf32H16RyX/?ref=app
6 Answers
+ 2
"20%" would be a string, you would need to convert it to a numeric type to do calculations with it
+ 1
1.If you want to get output without using html go for alert();
2.while taking input it is string by default so use parseInt(); to convert to int
3.tip calculation : put 100 in denominator
/*
let bill = parseInt(prompt("What's Your Bill?"));
let tip = (bill * whatTip)/100;
*/
hope this helps!
+ 1
let whatTip = prompt("What Type Of Tip Are You Looking for? 15% or 20%");
let bill = parseInt(prompt("What's Your Bill?"));
if(whatTip === "20%") {
let tip = (bill * 20)/100;
alert("Your Tip is: "+ tip);
bill=bill+tip;
alert("You New Total is: "+ bill);
}
else if(whatTip == "15%") {
let tip = (bill * 15)/100;
alert("Your Tip is: "+ tip);
bill=bill+tip;
alert("You New Total is: "+ bill);
}
//Is this how you want it to work just check once in playground
0
so would i use parseInt()? if so idk how i could put that into the code
0
it didnt work Himavanth
0
tysm!!