+ 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!!
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
+ 5
I have an idea: you can play with
Math.ceil(x)
or
Math.floor(x)
on the discounted result.
+ 1
I still can't figure it out test case 4 always fails! What percent is it using?
+ 1
They just fixed it! I emailed them! Try it now!
+ 1
info@sololearn.com š
+ 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
0
Ep
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?
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);
}
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);
}
}
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);
}
}
- 1
This is a task from Javascript course (phone app)
- 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
}
}
- 1
I can't get the link from app...
See the task and source code above!
- 1
As I said before, this is an exercise of Javascript course (phone app)
- 1
I'll try this! Thank you!!
- 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
}
}
}
- 1
- 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.