+ 7

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

@sololearn

3rd Dec 2020, 1:45 PM
Nivas MS
62 Answers
+ 41
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); }
3rd Dec 2020, 1:57 PM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 20
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?
9th Dec 2020, 12:20 PM
devfemibadmus
devfemibadmus - avatar
+ 10
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
7th Dec 2020, 1:40 AM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 9
bruh thats all what you need console.log(prices.map(x=>x+increase));
19th Jan 2021, 9:24 PM
Vlad
Vlad - avatar
+ 7
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); }
8th Jul 2021, 1:19 AM
Rahul Nizare
Rahul Nizare - avatar
+ 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); }
8th Jan 2021, 7:48 AM
Vijayanathan Menakan
Vijayanathan Menakan - avatar
+ 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); }
28th Jan 2021, 5:56 PM
Piriyanka Selvarajah
Piriyanka Selvarajah - avatar
+ 4
I cant remember [i] ever explained but ok
18th Feb 2021, 3:26 PM
coccyx
coccyx - avatar
+ 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?
7th Dec 2020, 12:30 AM
Justyna Dabrowska
Justyna Dabrowska - avatar
+ 3
Puedes realizarlo usando el método map(). const increment = prices.map(e => e + increase); console.log(increment);
10th Apr 2021, 1:53 AM
GavilanesJr.
GavilanesJr. - avatar
+ 3
# Use map function console.log(prices.map((p) => { return p+increase; }))
6th Nov 2021, 2:21 AM
GURURAJ KL
GURURAJ KL - avatar
+ 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); }
15th Jan 2021, 4:35 PM
Muhammad Riki Atsauri
Muhammad Riki Atsauri - avatar
+ 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); }
24th Feb 2021, 2:02 PM
UmarAli Mo'minjonov
UmarAli Mo'minjonov - avatar
+ 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
15th Apr 2021, 4:15 AM
ajay T
ajay T - avatar
+ 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) }
29th Apr 2021, 7:23 AM
Shameem Noormamode
+ 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); }
21st May 2021, 9:52 PM
Adebisi Ola-Adebomi
+ 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); } Good Luck
13th Dec 2021, 2:14 AM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
+ 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); }
8th Jan 2022, 4:32 AM
PREETHI T G
PREETHI T G - avatar
+ 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)+" ]"); }
22nd Jan 2022, 10:23 AM
Hammami Hadil
Hammami Hadil - avatar
+ 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); }
15th Jul 2022, 8:40 AM
Ashish Rawat
Ashish Rawat - avatar