1

I tried to multiply each number whose index number is an even number by two, and that worked fine. Still, the problem lies here: If any of the results is greater than or equal to 10, then add up the two numbers, for example, if one of the results is 12, then add up 1 and 2, which should be equal to 3. So this is what I tried:

var num = 122345643345673;
var convNum = num.toString();
var aftertoString = convNum.split("");
for(let i = 1; i < aftertoString.length; i++){
    if (i % 2 == 0) {
        var multi = aftertoString[i] * 2;
        if(multi > 10){
            var multiStringed = multi.toString();
            var aftermutliStringed = multiStringed.split("");
            var first = parseInt(aftermutliStringed[2])
            var multi = first + first;
        }
        console.log(multi);
    }
    
}

Since any index of the "aftermultiSringed" array is not a number, I tried to convert it to a number using the "parseInt()" method, but the result is NaN, please why am I getting this.

Samuel Emeka
  • 73
  • 1
  • 9

1 Answers1

2

The method parseInt usage is incorrect.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt

// var first = aftermultiStringed[1].parseInt();
var first = parseInt(aftermultiStringed[1]);