ماهو النقص في ال code حتى يعطي الناتج ٣٦ فقط؟؟ وأريد أن يجري مقدار الزيادة على كل عناصر المصفوفة | Sololearn: Learn to code for FREE!
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); }

23rd Jan 2022, 5:10 PM
Zina Shekh Alzoor
Zina Shekh Alzoor - avatar
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.
23rd Jan 2022, 5:21 PM
Simba
Simba - avatar
+ 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);
23rd Jan 2022, 9:27 PM
Mohammed
+ 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);
23rd Jan 2022, 9:49 PM
Mohammed
+ 3
لذلك ، يمكنك طباعة المصفوفة بدلاً من العناصر console.log(prices)
24th Jan 2022, 4:43 AM
Simba
Simba - avatar
+ 2
I understand English but weak in it, Do you mean like this? It also didn't work
23rd Jan 2022, 5:31 PM
Zina Shekh Alzoor
Zina Shekh Alzoor - avatar
+ 2
i[0] +=increase; i[1] +=increase; i[2] +=increase; i[3] +=increase;
23rd Jan 2022, 5:33 PM
Zina Shekh Alzoor
Zina Shekh Alzoor - avatar
+ 2
Output is Undefined
23rd Jan 2022, 9:44 PM
Zina Shekh Alzoor
Zina Shekh Alzoor - avatar
+ 2
مازال الناتج خاطئ، يعطي ناتج واحد فقط بدلا من أن يجمع كل عنصر مع مقدار الزيادة
23rd Jan 2022, 10:04 PM
Zina Shekh Alzoor
Zina Shekh Alzoor - avatar
+ 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); }
24th Jan 2022, 9:53 AM
Mohammed
+ 1
for(let i=0; i<prices.length; i++) { prices[i]+=increase; console.log(prices[i]); } هذا البرنامج يطبع جميع عناصر السعر مع مقدار الزيادة.
23rd Jan 2022, 10:10 PM
Mohammed
+ 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.
24th Jan 2022, 9:48 AM
Zina Shekh Alzoor
Zina Shekh Alzoor - avatar
+ 1
هذا السؤال
24th Jan 2022, 9:48 AM
Zina Shekh Alzoor
Zina Shekh Alzoor - avatar
+ 1
شكرًا جزيلًا لك
24th Jan 2022, 9:56 AM
Zina Shekh Alzoor
Zina Shekh Alzoor - avatar
+ 1
Zina Shekh Alzoor No problem.
24th Jan 2022, 9:56 AM
Mohammed
0
أعطى نفس الخرج المتوقع ومع ذلك يعطي أنه خرج خاطئ؟؟!! هل ممكن لان الخرج نفس الارقام ولكن بشكل عمودي وهم يريدون الخرج بشكل افقي ومثل شكل المصفوفة!!
23rd Jan 2022, 10:25 PM
Zina Shekh Alzoor
Zina Shekh Alzoor - avatar
0
مازال يعطي خطأ، لأنه يعطي 4 نتائج والأخيرة فقط كالنتيجة المتوقعة
24th Jan 2022, 8:42 AM
Zina Shekh Alzoor
Zina Shekh Alzoor - avatar
0
Zina Shekh Alzoor ما هو السؤال بالكامل ؟
24th Jan 2022, 9:32 AM
Mohammed
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); }
24th Jan 2022, 6:26 PM
Swati Singh
Swati Singh - avatar
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.
25th Jan 2022, 1:34 PM
DarkHollow
DarkHollow - avatar
25th Jan 2022, 4:48 PM
Techno.uae
Techno.uae - avatar