Can you help me figure out this error | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Can you help me figure out this error

https://code.sololearn.com/WQelFu58r1RL/?ref=app Am trying to multiply a list of array by 2 but am a null output

14th Aug 2020, 5:30 AM
Tijan
Tijan - avatar
8 Antworten
+ 2
Tijan , You changed code in HTML tab not in JS😁
14th Aug 2020, 5:47 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 2
num[i] = num[i] * 2; What you had done is multiply by the variable itself not by items of variable :)
14th Aug 2020, 5:37 AM
Kuber Acharya
Kuber Acharya - avatar
+ 2
You want to multiply every element of array by 2. right? see this line: ``` num[i] = num * 2; ``` num*2 is resulting into NaN(Not a Number), because you are trying to perform arithmetic operation on non-numeric type. valid statement will be: ``` num[i] = num[i] * 2; ```
14th Aug 2020, 5:40 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 2
🇮🇳Omkar🕉 yeah 😅 thanks man i apprecitate
14th Aug 2020, 5:48 AM
Tijan
Tijan - avatar
0
Kuber Acharya thank you but can you explain it better am kinda new to this language
14th Aug 2020, 5:41 AM
Tijan
Tijan - avatar
0
🇮🇳Omkar🕉 am still getting the same error
14th Aug 2020, 5:44 AM
Tijan
Tijan - avatar
0
i just updated the code
14th Aug 2020, 5:46 AM
Tijan
Tijan - avatar
0
Tijan In your code it should be num[i] = num[i]*2 but not num[i] = num*2 -- Suggestion: You can use Array.map() method for that purpose. It returns an array and you can save that to a new variable. You can do a whole lot of things, multiply or divide with a constant number and more. See more about it here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map Ex. -------- let arr = [1,2,3,4,5]; let doubleArr = arr.map( (num) => { return num*2; } // doubleArr = [2,4,6,8,10] --------
14th Aug 2020, 6:10 AM
Hanuma Ukkadapu
Hanuma Ukkadapu - avatar