+ 5

JavaScript Math Operator 2 Quiz!

I need help solving the JavaScript Math Operator 2 quiz. Can someone please help me. function main() { var oldPrice = parseInt(readLine(5), 10) // your code goes here var newPrice =(oldPrice - 20% ); This is what I have so far

6th Jan 2021, 11:01 AM
Lisa :)
Lisa :) - avatar
9 Answers
+ 4
Okay, a couple of errors: - readLine() shouldn't take 5 as a parameter. Try removing it. - Javascript doesn't compute percentages for you, so 20% wouldn't be valid code. Actually, the % operator returns the remainder when a number is divided by a number. This means that you need to fix newPrice. To calculate it, you need to subtract 20%(which, hint hint, is 0.2 in decimal) of oldPrice from oldPrice.
6th Jan 2021, 11:50 AM
Jianmin Chen
Jianmin Chen - avatar
+ 3
You're super close - to get 20% of oldPrice you need to multiply oldPrice by 0.2;)
6th Jan 2021, 12:11 PM
Jianmin Chen
Jianmin Chen - avatar
+ 2
Thank you šŸ˜šŸ‘! I tried 0.2 but it wasn't working for me but I'll try it again Here's what I changed: function main() { var oldPrice = parseInt(readLine(), 10) // your code goes here var newPrice =(oldPrice - 0.2 ); I still isn't working Oh wait I think I know what I forgot
6th Jan 2021, 11:54 AM
Lisa :)
Lisa :) - avatar
+ 1
Thank youšŸ˜šŸ‘
6th Jan 2021, 12:18 PM
Lisa :)
Lisa :) - avatar
+ 1
I still can't get itšŸ˜‚: function main() { var oldPrice = parseInt(readLine(), 10) // your code goes here var newPrice =(oldPrice * 0.2 );
6th Jan 2021, 12:25 PM
Lisa :)
Lisa :) - avatar
+ 1
It's a mix of your two answers: oldPrice = oldPrice - (oldPrice * 0.2);
6th Jan 2021, 2:20 PM
Jianmin Chen
Jianmin Chen - avatar
+ 1
Ooooh thanks I'll try it
6th Jan 2021, 2:32 PM
Lisa :)
Lisa :) - avatar
+ 1
help me please) function main() { var oldPrice = parseInt(readLine(), 10) // your code goes here return oldPrice*0,8; } isnā€™t work, why?
7th Jan 2021, 10:05 AM
Š Š¾Š¼Š°Š½
Š Š¾Š¼Š°Š½ - avatar
+ 1
Try this: function main() { var oldPrice = parseInt(readLine(), 10) // your code goes here var newPrice = oldPrice - oldPrice/5; console.log(newPrice); }
13th Jan 2021, 10:30 AM
Barbu Vulc
Barbu Vulc - avatar