+ 3
Can someone help me understand what is needed to resolve this challenge
Math Operators 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 Explanation 20 percent of 100 equals to 20 (100 * 20/100), so the discounted price will be 80 (100 - 20). Remember the division (/) and multiplication (*) operators.
7 Respostas
+ 4
three line code
1. take user Input ;
2. calculate the discount using formula(price - discount/100 * price)
3. Output the discount
+ 3
* take input
* find discount of 20% of input
* subtract discount from total and display result..
What is your difficulty? share your try..
+ 3
Here's my current code
function main() {
var oldPrice = parseInt(readLine(), 10)
// your code goes here
var oldPrice = 100
var sale = 20
var savings = (oldPrice * sale) / 100
var newPrice = oldPrice - savings
console.log(newPrice)
+ 3
Comment or remove this line :
var oldPrice=100
As you already defined oldPrice and it replacing input value to 100 , logic error.. ( put end } )
+ 3
Thank you that worked
+ 1
//so we don’t overwhelm you, we’ve hidden the code that executes the input
function main() {
var oldPrice = parseInt(readLine(), 10)
// your code goes here
var oldPrice = 100
var sale = 20
var savings = (oldPrice * sale) / 100
var newPrice = oldPrice - savings
console.log(newPrice)
}
function main() {
var oldPrice = parseInt(readLine(), 10)
// your code goes here
var discount = (oldPrice - (oldPrice *20/100) );
console.log(discount);
}
Good Luck