Tip Converter | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

18th Apr 2022, 4:11 PM
Junior
Junior - avatar
6 Answers
+ 2
"20%" would be a string, you would need to convert it to a numeric type to do calculations with it
18th Apr 2022, 4:15 PM
Lisa
Lisa - avatar
+ 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!
18th Apr 2022, 4:26 PM
Himavanth
Himavanth - avatar
+ 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
18th Apr 2022, 4:39 PM
Himavanth
Himavanth - avatar
0
so would i use parseInt()? if so idk how i could put that into the code
18th Apr 2022, 4:19 PM
Junior
Junior - avatar
0
it didnt work Himavanth
18th Apr 2022, 4:30 PM
Junior
Junior - avatar
0
tysm!!
18th Apr 2022, 4:47 PM
Junior
Junior - avatar