- 1
Math Operator 2 JS
Hello Im new What is wrong? I cant finish this exercise... var price = 100; var discount = 20; var newPrice = price - (price * discount) / 100; console.log(newPrice);
8 Antworten
+ 5
//Try this
function main() {
var oldPrice = parseInt(readLine(), 10)
//var price = 100;
var discount = 20/100;
var newPrice = oldPrice - (discount*oldPrice)
console.log(newPrice);
+ 3
Mateusz Wielgat The code works properly.
https://code.sololearn.com/W663kJcG1NO8/?ref=app
+ 3
Thank you very much. Now I see where was problem I did not take the old price.
+ 2
Time to go shopping!
Everything in the store has been discounted by 20%.
You are given a program that takes the price of an item as input. Complete the program so that it outputs the discounted price to the console.
Sample Input
100
Sample Output
80
//so we don’t overwhelm you, we’ve hidden the code that executes the input
function main() {
var oldPrice = parseInt(readLine(), 10)
var price = 100;
var discount = 20;
var newPrice = price - (price * discount) / 100;
console.log(newPrice);
I have three test case , Ive pass one but doesn't want to pass the exercise
+ 1
Hi,
this code will pass all 4 tests
var oldPrice = parseInt(readLine(), 10)
var Price = oldPrice*1
var Discount = 20
var newPrice = Price - (Discount * Price)/100
console.log(newPrice)
at least it worked for me ;)
Greetings!
+ 1
You need it to transform the price into numeric data. Otherwise the system will come back with no numeric data on the tests.
0
why did you use: var Price = oldPrice*1
??
- 1
function main() {
var oldPrice = parseInt(readLine(), 10)
var Price = oldPrice*1
var Discount = 20
var newPrice = Price - (Discount * Price)/100
console.log(newPrice)
}