+ 2
How do I make the output like an array with third brackets like [a+1,b+1,c+1]? My code is giving the output in different lines.
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. My code: function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here for(var i =0;i<4;i++){ prices[i] += increase ; console.log(prices[i]); } }
2 Réponses
+ 3
Nvm I worked it out.
My code in case anyone wonders where the issue was:
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
for(var i =0;i<4;i++){
prices[i] += increase ;
}
console.log(prices);
}
+ 3
In the first case u were printing the array content looping on each index.
In your second case (solution) you are printing the array itself. So yeah! Congratz for solving this yourself