You are working on a Store Manager program, which stores the prices in an array. You need to add functionality to increase the | Sololearn: Learn to code for FREE!

+5

You are working on a Store Manager program, which stores the prices in an array. You need to add functionality to increase the

@sololearn

12/3/2020 1:45:18 PM

Nivas MS

51 Answers

New Answer

+31

You need to tag JavaScript and code coach instead. This problem "store manager" is very simple, you need to increase each items of the array. The following code will be helpful. 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); }

+22

Why is there prices.length-1 and not just prices.length? What does it do? Im confused 🤷‍♀️ I know it makes it flexible in case adding a new price but in what way?

+10

bruh thats all what you need console.log(prices.map(x=>x+increase));

+9

Justyna Dabrowska yes we can simply write price.length but loop should be for(var i=0;i<prices.length;i++){} Not for(var i=0;i<=prices.length;i++){} Simply condition part of the loop should be i<price.length

+5

Simple way to solve : function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here //var prices1=0; for(var i=0;i<4;i++){ prices[i] = prices[i]+increase; } console.log(prices); }

+4

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); }

+4

I cant remember [i] ever explained but ok

+3

Why is there prices.length-1 and not just prices.length? What does it do? Im confused 🤷‍♀️ I know it makes it flexible in case adding a new price but in what way?

+3

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); }

+2

Puedes realizarlo usando el método map(). const increment = prices.map(e => e + increase); console.log(increment);

+1

function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here for (i=0; i < prices.length; i++) { prices[i] += increase; } console.log(prices); }

+1

function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //ваш код array = []; for(n=0; n<prices.length; n++){ array.push(prices[n] + increase); } console.log(array); }

+1

function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here prices.forEach(inc => console.log (inc+increase)) } why this is not passing the testcase even though its correct

+1

Tried for a long time and finally had this one: function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here var newPrices = []; for (let num of prices){ let pri = num += increase; newPrices.push(pri); } console.log(newPrices) }

+1

function main() { let increase = parseInt(readLine(), 10); let prices = [98.99, 15.2, 20, 1026]; //your code goes here for(i=0; i<prices.length; i++) { prices[i] += increase; } console.log(prices); }

+1

# Use map function console.log(prices.map((p) => { return p+increase; }))

+1

function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here for (var x = 0;x < prices.length;x++) { prices[x]= prices[x]+increase; } console.log(prices); }

+1

function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here console.log("[ "+parseFloat(prices[0]+increase)+", "+parseFloat(prices[1]+increase)+", "+parseFloat(prices[2]+increase)+", "+parseFloat(prices[3]+increase)+" ]"); }

+1

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

// function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code var newPrice=[ ]; for(let i=0 ;i <prices.length ;i++){ var x=prices[i]+increase; newPrice.push(x); } console.log(newPrice ); }