New course! Every coder should learn Generative AI!
Try a free lesson- 1
ู ุงูู ุงูููุต ูู ุงู code ุญุชู ูุนุทู ุงููุงุชุฌ ูฃูฆ ููุทุุ ูุฃุฑูุฏ ุฃู ูุฌุฑู ู ูุฏุงุฑ ุงูุฒูุงุฏุฉ ุนูู ูู ุนูุงุตุฑ ุงูู ุตูููุฉ
function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here var sum =0; for (var i=0; i<prices.length ;i++) sum +=increase; console.log (sum); }
20 Answers
+ 6
I believe you can understand English as well.
Here, you're adding a same value (increase) with sum for each iteration. But, task says that you need to add the value with price array elements and print the updated array.
You can use i as index of array elements and add with increase.
+ 3
Zina Shekh Alzoor
Use the following statement instead.
for(let i=0; i<prices.length; i++){
sum[i] += increase;
console.log(sum[i] );
}
edit:
for(let i=0; i<prices.length; i++){
prices[i]+= increase;
sum+=prices[i];
}
console.log(sum);
+ 3
Zina Shekh Alzoor
I'm so sorry, I made a mistake,
for(let i=0; i<prices.length; i++){
prices[i] += increase;
sum+= prices[i];
}
console.log(sum);
+ 3
ูุฐูู ุ ูู
ููู ุทุจุงุนุฉ ุงูู
ุตูููุฉ ุจุฏูุงู ู
ู ุงูุนูุงุตุฑ
console.log(prices)
+ 2
I understand English but weak in it, Do you mean like this? It also didn't work
+ 2
i[0] +=increase;
i[1] +=increase;
i[2] +=increase;
i[3] +=increase;
+ 2
Output is Undefined
+ 2
ู
ุงุฒุงู ุงููุงุชุฌ ุฎุงุทุฆุ ูุนุทู ูุงุชุฌ ูุงุญุฏ ููุท ุจุฏูุง ู
ู ุฃู ูุฌู
ุน ูู ุนูุตุฑ ู
ุน ู
ูุฏุงุฑ ุงูุฒูุงุฏุฉ
+ 2
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
for (let i=0; i<prices.length ;i++)
{ prices[i]+=increase; }
console.log(prices);
}
+ 1
for(let i=0; i<prices.length; i++)
{
prices[i]+=increase;
console.log(prices[i]);
}
ูุฐุง ุงูุจุฑูุงู
ุฌ ูุทุจุน ุฌู
ูุน ุนูุงุตุฑ ุงูุณุนุฑ ู
ุน ู
ูุฏุงุฑ ุงูุฒูุงุฏุฉ.
+ 1
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.
+ 1
ูุฐุง ุงูุณุคุงู
+ 1
ุดูุฑูุง ุฌุฒูููุง ูู
+ 1
Zina Shekh Alzoor
No problem.
0
ุฃุนุทู ููุณ ุงูุฎุฑุฌ ุงูู
ุชููุน ูู
ุน ุฐูู ูุนุทู ุฃูู ุฎุฑุฌ ุฎุงุทุฆุุ!! ูู ู
ู
ูู ูุงู ุงูุฎุฑุฌ ููุณ ุงูุงุฑูุงู
ูููู ุจุดูู ุนู
ูุฏู ููู
ูุฑูุฏูู ุงูุฎุฑุฌ ุจุดูู ุงููู ูู
ุซู ุดูู ุงูู
ุตูููุฉ!!
0
ู
ุงุฒุงู ูุนุทู ุฎุทุฃุ ูุฃูู ูุนุทู 4 ูุชุงุฆุฌ ูุงูุฃุฎูุฑุฉ ููุท ูุงููุชูุฌุฉ ุงูู
ุชููุนุฉ
0
Zina Shekh Alzoor
ู
ุง ูู ุงูุณุคุงู ุจุงููุงู
ู ุ
0
ู
ุงูู ุงูููุต ูู ุงู code ุญุชู ูุนุทู ุงููุงุชุฌ ูฃูฆ ููุทุุ ูุฃุฑูุฏ ุฃู ูุฌุฑู ู
ูุฏุงุฑ ุงูุฒูุงุฏุฉ ุนูู ูู ุนูุงุตุฑ ุงูู
ุตูููุฉ
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
var sum =0;
for (var i=0; i<prices.length ;i++)
sum +=increase;
console.log (sum);
}
0
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;i++){
prices[i] += increase;
}
console.log(prices);
}
ุฅุณุชุนู
ู ูุฐุง ุงูููุฏ ุงูุฎูู ุงููุญูุฏ ุงูุฐู ูู ุชูู ุงูุฃููุงุฏ ูู ู
ูุงู console.log.