0
How do I solve the Store Manager Code Project? See 44 CODE PROJECT under JavaScript for description.
Here is my code. It solves Test Case #1 but not Test Case #2 which is to increase each variable by 100. function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here for (var increase = 0; increase < prices.length; increase++) { prices[increase] += 9 } console.log(prices); }
3 Réponses
+ 3
// try this
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
for (var i=0; i<prices.length; i++) prices[i] += increase;
console.log(prices);
+ 1
It worked. Thank you.
0
We can do much better, we can just call a for loop telling to increase for each iteration of prices that it encounter to increase the price.
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
for(x in prices) //for each iteration in prices
prices[x] += increase // do price + increase
console.log(prices);
}