Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Square Every Digit


function squareDigits(num){
    
    //first change the number to string 

  let strnum = String(num)
  let result = ''

  //Do search of the String (number)

  for(let i =0; i<strnum.length;i++){
      //For math we need change it again to int 
     let squared = parseInt(strnum[i])*parseInt(strnum[i])
     //and after that change again to string 
     result = result+ String(squared)
      
  }
  // The final change to int 

  return parseInt(result)
  
  }

  console.log(squareDigits(9119))
 
PREVIOUS NEXT
Tagged: #Square #Every #Digit
ADD COMMENT
Topic
Name
1+5 =