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
9 Réponses
+ 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)
+ 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.
+ 2
d shaw
No need of another variable, you can use the same.
Also just print prices
console.log(prices); //this is enough
+ 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()
+ 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,"]");
0
What is your difficulty there..?
Just add input value to each array element and display array..
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.
- 2
😂🤣😂😂😂😂