how can help we with big sale of javacript excersie?
I complet one task but when I write another code it not accept what I should do to solve it
2/6/2021 4:40:05 AM
Farhad Faqeri
6 Answers
New Answerthis is the solution. function main() { var oldPrice = parseInt(readLine(),10); console.log(oldPrice/100*80); }
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) //your code goes here } ^That is the problem and I am also stuck... I tried like this: function main(){ var oldPrice = parseInt(readLine(),10) var percentage= (oldPrice*20/100); var newPrice =oldPrice - percentage; console.log(newPrice); ^It worked for 1 case but ask for at least 2 more different input and outputs (that was not in the question and also has 2 more "secret" answers). So I wondered if there is a way to make this var oldPrice has different values, I tried to give different values after the console.log and tested if the value changed but broke the code hahaha So please 🆘
function main() { var oldPrice = parseInt(readLine(), 10) // your code goes here var newPrice= oldPrice*80/100 console.log(newPrice) }
function main() { var oldPrice = parseInt(readLine(), 10) var discount = oldPrice * 20/100 var newPrice = oldPrice - discount console.log(newPrice) } I just found the discount first, and I deducted the discount from the old price. That gave me the new price. Simple