Can someone help me understand what is needed to resolve this challenge | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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.

8th Dec 2021, 11:53 AM
Mataia
6 Answers
+ 4
three line code 1. take user Input ; 2. calculate the discount using formula(price - discount/100 * price) 3. Output the discount
8th Dec 2021, 12:01 PM
Pariket Thakur
Pariket Thakur - avatar
+ 3
* take input * find discount of 20% of input * subtract discount from total and display result.. What is your difficulty? share your try..
8th Dec 2021, 12:00 PM
Jayakrishna 🇮🇳
+ 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)
8th Dec 2021, 12:13 PM
Mataia
+ 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 } )
8th Dec 2021, 12:21 PM
Jayakrishna 🇮🇳
+ 3
Thank you that worked
8th Dec 2021, 12:29 PM
Mataia
+ 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
25th Jan 2022, 3:10 AM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar