0
Need help in calculating percentage in JavaScript?
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). what's wrong in my code? //so we don’t overwhelm you, we’ve hidden the code that executes the input function main() { var oldPrice = parseInt(readLine(), 10) var percent = 20/100 * oldPrice ; console.log(percent ) }
6 Respostas
+ 2
Bilal Ahmad You are trying to output the reduced price rather than the discounted price ...
so it should be like :
after input ,
var x=20/100*oldPrice; // 20
console.log(oldPrice-x); //like in the eg:100-20
0
Post your attempt first to get help from the community...
Edit : Question edited ...
0
thanx buddy
0
Wlcm :)
0
// your code goes here
var x=20/100*oldPrice; // 20
console.log(oldPrice-x);
- 2
added my attempt