+ 6

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!!

25th Oct 2020, 1:00 PM
Doc Waxler
Doc Waxler - avatar
20 Respostas
+ 14
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 this.price = price - ((discount/100)*price) } } It shows at the hint sections how to calculate it
19th Jun 2021, 9:30 AM
Agon Istrefi
+ 5
I have an idea: you can play with Math.ceil(x) or Math.floor(x) on the discounted result.
25th Oct 2020, 4:50 PM
JaScript
JaScript - avatar
+ 1
I still can't figure it out test case 4 always fails! What percent is it using?
28th Oct 2020, 11:30 AM
Corey Fleming
Corey Fleming - avatar
+ 1
They just fixed it! I emailed them! Try it now!
28th Oct 2020, 12:58 PM
Corey Fleming
Corey Fleming - avatar
+ 1
info@sololearn.com šŸ™‚
28th Oct 2020, 1:40 PM
Corey Fleming
Corey Fleming - avatar
+ 1
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 this.price = price - ((discount/100)*price) } } Good Luck
25th Jan 2022, 8:30 AM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
0
Ep
25th Oct 2020, 5:29 PM
Elena IVANOVA
Elena IVANOVA - avatar
0
There's my code I don't know what could possibly be wrong!
28th Oct 2020, 11:32 AM
Corey Fleming
Corey Fleming - avatar
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?
28th Oct 2020, 1:28 PM
Doc Waxler
Doc Waxler - avatar
0
@ Corey Fleming try this- function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here for(var i=0;i<=prices.length-1;i++){ prices[i]=prices[i]+increase; } console.log(prices); }
12th Jan 2021, 6:54 PM
Priya Ghosh
Priya Ghosh - avatar
0
This is my solution... 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 this.price = this.price * (1-discount/100); } }
12th May 2021, 6:14 PM
Rahul Tiwari
0
You can try this. 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 this.price = (price-(discount/100)*price); } }
7th Feb 2023, 1:21 PM
Vinicius Figueiredo
Vinicius Figueiredo - avatar
- 1
This is a task from Javascript course (phone app)
25th Oct 2020, 3:30 PM
Doc Waxler
Doc Waxler - avatar
- 1
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 } }
25th Oct 2020, 3:50 PM
Doc Waxler
Doc Waxler - avatar
- 1
I can't get the link from app... See the task and source code above!
25th Oct 2020, 3:58 PM
Doc Waxler
Doc Waxler - avatar
- 1
As I said before, this is an exercise of Javascript course (phone app)
25th Oct 2020, 4:10 PM
Doc Waxler
Doc Waxler - avatar
- 1
I'll try this! Thank you!!
25th Oct 2020, 4:56 PM
Doc Waxler
Doc Waxler - avatar
- 1
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 } } }
28th Oct 2020, 11:31 AM
Corey Fleming
Corey Fleming - avatar
- 1
15th Jan 2021, 6:35 PM
RUSHIL PUJARA
RUSHIL PUJARA - avatar
- 2
You are working on a Store Manager program, which stores the prices in an array. You need to add functionality to increase the prices by the given amount. The increase variable is taken from user input. You need to increase all the prices in the given array by that amount and output to the console the resulting array.
7th Dec 2020, 5:47 PM
Achal Sakure
Achal Sakure - avatar