+ 2
Not getting completed notice after entering code for project
I'm working on JavaScript, and the #44 Code Project "Store Manager" Even though my output matches what Sololearn expected, It is not giving me a completed message. Here's my code: function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here x=prices[0]+increase; y=prices[1]+increase; z=prices[2]+increase; t=prices[3]+increase; console.log("["+x+",",y+",",z+",",t+"]") }
4 ответов
+ 4
Stacey Prahl , according to your code change it to =>
prices[0]+= increase;
prices[1]+= increase;
prices[2]+= increase;
prices[3]+= increase;
console.log(prices);
+ 3
Stacey Prahl ,
following the hints from TheWh¡teCat 🇧🇬 you will be able to solve this task.
just let me give you a hint:
the way this solution is done is like hard coded. it does only work with 4 elements in the list (imagine there is a list with 250 elements - this should nit be done in the current way).
a more suitable way that will work with any number of elements in the list is to use a for loop.
you can find samples in the tutorial.
happy coding!
+ 1
Stacey Prahl
Another cool method is using functional programming:
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
prices=prices.map((p)=>p+increase);
console.log(prices);
}
0
thanks I'll try that