var inp = document.getElementById('inp'); function digi(){ var n = inp.value; var digit = parseInt(n, 2); var modified = String(digit); var arra = digit.split(','); for(var i = 2; i < n; i++){ console.log(digit); for(var j = 0; j < arra.length; j++){ if(j == 1 ){ var opp = []; var arr = opp.push(j); } else if(j == 0){ var pop = []; var arr2 = pop.push(j); } if(arr.length > arr2.length){ console.log(n); } } } } digi(55); 

Hello, I can not understand why split does not work In the console it says that split is not a function I tried instead of writing the value in the variable n to write the number directly to the function parameter, did not help

  • you have a variable digit what type? Exactly string? check by hand - Lolidze
  • try digit.toString () where you assign modified - Kayrosik
  • changing returns NaN or something like that and therefore the split function swears - Daniel
  • None of this helped - Podhou

2 answers 2

 var digit = parseInt(n, 2); var modified = String(digit); var arra = digit.split(','); 

digit to which split() is applied is a number (see the first line). split() must be attached to modified from the second line:

 var digit = parseInt(n, 2); var modified = String(digit); var arra = modified.split(','); 

     var inp = document.getElementById('inp'); function digi(){ var n = inp.value; var digit = parseInt(n, 10); var arra = n.split(','); console.log(arra); for(var i = 2; i < n; i++){ console.log(digit); for(var j = 0; j < arra.length; j++){ if(j == 1 ){ var opp = []; var arr = opp.push(j); } else if(j == 0){ var pop = []; var arr2 = pop.push(j); } if(arr.length > arr2.length){ console.log(n); } } } } digi(55); 
     <input id="inp" value="5,444">