Search
 
SCRIPT & CODE EXAMPLE
 

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))
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery check is select 
Javascript :: html to pdf nodejs 
Javascript :: parseint 
Javascript :: how to swap two elements in an array javascript 
Javascript :: generate angular component in a folder 
Javascript :: javascript Given a base-10 integer, , convert it to binary (base-10). 
Javascript :: how to run a bash script with node js 
Javascript :: checking scroll position with js 
Javascript :: nodejs delete in mysql 
Javascript :: How to globally use Axios instance and interceptors in Vue.js 
Javascript :: nextjs docs 
Javascript :: patterns in javascript 
Javascript :: update angular project 
Javascript :: datepicker min max date 
Javascript :: javascript array filter elements greater than 
Javascript :: how to convert an array into single quote strings 
Javascript :: string into json javascript 
Javascript :: try catch async await 
Javascript :: dropzone remove error file 
Javascript :: Check if an array contains a object in javascript 
Javascript :: get javascript component position 
Javascript :: javascript find the longest string in array 
Javascript :: how to make a grocery list in javascript 
Javascript :: upi id regex 
Javascript :: fetch json data into array 
Javascript :: innerhtml 
Javascript :: node-schedule npm 
Javascript :: get only string from html description javascript 
Javascript :: get param from url jquery 
Javascript :: chart.js clear data 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =