What's wrong with this code? Please, help! | SoloLearn: Learn to code for FREE!

+2

What's wrong with this code? Please, help!

Hi guys! What is wrong with this code? https://code.sololearn.com/WTb62F0rrzhQ/#js Four out of five tests pass, one fails ... Because of this, I can not complete the task :( What an error - does not show ... Please, help!!

10/25/2020 1:00:20 PM

Doc Waxler

17 Answers

New Answer

+3

I have an idea: you can play with Math.ceil(x) or Math.floor(x) on the discounted result.

+1

+1

They just fixed it! I emailed them! Try it now!

+1

0

Where you did find it? var prodID = readLine() var price = parseInt(readLine(),10) var discount = parseInt(readLine(),10)

0

This is a task from Javascript course (phone app)

0

A store manager needs a program to set discounts for products. The program should take the product ID, price and discount as input and output the discounted price. However, the changePrice method, which should calculate the discount, is incomplete. Fix it! Sample Input LD1493 1700 15 Sample Output LD1493 price: 1700 LD1493 new price: 1445 ==================== function main() { var prodID = readLine(); var price = parseInt(readLine(),10); var discount = parseInt(readLine(),10); var prod1= new Product(prodID, price); console.log(prod1.prodID + " price: " + prod1.price); prod1.changePrice(discount); console.log(prod1.prodID + " new price: " + prod1.price); } function Product(prodID, price) { this.prodID = prodID; this.price = price; this.changePrice = function(discount) { //your code goes here } }

0

I cannot find it. Do you can provide the link to it?

0

I can't get the link from app... See the task and source code above!

0

This cannot work here. What makes you think that it is JavaScript?

0

As I said before, this is an exercise of Javascript course (phone app)

0

Then have fun

0

I'll try this! Thank you!!

0

I still can't figure it out test case 4 always fails! What percent is it using?

0

function main() { var prodID = readLine(); var price = parseInt(readLine(),10); var discount = parseInt(readLine(),10); var prod1= new Product(prodID, price); console.log(prod1.prodID + " price: " + prod1.price); prod1.changePrice(discount); console.log(prod1.prodID + " new price: " + prod1.price); } function Product(prodID, price) { this.prodID = prodID; this.price = price; this.changePrice = function(discount) { //your code goes here if (discount <= 100) { var realpercent = 1- (discount * .01) var realdiscount = this.price * realpercent this.price = realdiscount } if (discount >= 100) { this.price = 0 } } }

0

There's my code I don't know what could possibly be wrong!

0

O!... Thanks a lot, mate! Now it's working!! I guessed that it was just a bug. What's the address you emailed them?