0

Help me to complete the javascript course. I am stuck at 98%.

Here is the question 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. Please help me to complete the code and course. https://code.sololearn.com/WAa5u6bKRu89/?ref=app

25th Jun 2022, 7:59 AM
Dipankar Shaw
Dipankar Shaw - avatar
9 Answers
+ 3
d shaw There are only 4 items not 5 No need to get percentage just increase prices No need to print value one by one just print prices for(let i=0;i<4;++i){ prices[i] += increase; } console.log(prices)
25th Jun 2022, 9:04 AM
A͢J
A͢J - avatar
+ 2
for(let i=0;i<4;++i){ // array has only 4 elements, so only loop 4 times.. prices[i] += prices[i]*(increase/100); }// use prices[i] , not prices here.
25th Jun 2022, 9:02 AM
Jayakrishna 🇮🇳
+ 2
d shaw No need of another variable, you can use the same. Also just print prices console.log(prices); //this is enough
25th Jun 2022, 9:12 AM
A͢J
A͢J - avatar
+ 1
Create a new variable that prompt use for input, then add to each of the given array. Something like this function main() { var prices = [98.99, 15.2, 20, 1026]; //your code goes here let increase = +prompt ("enter a no"); let newPrices = prices.map((value) => value + increase) console.log(newPrices ) } main()
25th Jun 2022, 8:33 AM
Muhammad Awwal Yusuf
Muhammad Awwal Yusuf - avatar
+ 1
Your new array has 5 elements. But original has only 4 elements. No need new array. And to display just use console.log( newprices ) ; // how you want to display? edit: d shaw console.log(...newprice); // space separated console.log("[",newprice,"]");
25th Jun 2022, 9:13 AM
Jayakrishna 🇮🇳
0
What is your difficulty there..? Just add input value to each array element and display array..
25th Jun 2022, 8:26 AM
Jayakrishna 🇮🇳
0
Here i have to increase the array by provided percentage. That increament is the problem first element is increasing properly but others aren't.
25th Jun 2022, 8:32 AM
Dipankar Shaw
Dipankar Shaw - avatar
25th Jun 2022, 9:07 AM
Dipankar Shaw
Dipankar Shaw - avatar
- 2
😂🤣😂😂😂😂
27th Jun 2022, 5:06 AM
Himanshu Kumar
Himanshu Kumar - avatar