Home > Web Front-end > JS Tutorial > body text

Number Patterns in Javascript

PHPz
Release: 2024-08-17 15:14:32
Original
381 people have browsed it

Number Patterns in Javascript

Here are some of the number Patterns in javascript that are mostly asked in Interview Questions.

function printNum(){
 for(let i=1; i<=4; i++){
     let finalOutput = '';
     for(let j=1; j<=i; j++){
         finalOutput += i
     }
     console.log(finalOutput)
 }   
}

printNum()

output
1
1 2
1 2 3
1 2 3 4
Copy after login
function printNum(){
 for(let i=1; i<=4; i++){
     let finalOutput = '';
     for(let j=1; j<=i; j++){
         finalOutput += j
     }
     console.log(finalOutput)
 }   
}

printNum()

output
1
1 2
1 2 3
1 2 3 4
Copy after login
function printNum(){
 for(let i=1; i<=4; i++){
     let finalOutput = '';
     for (let k=1; k<=4-i;k++){
         finalOutput += " "
     }
     for(let j=1; j<=i; j++){
         finalOutput += j
     }
     console.log(finalOutput)
 }   
}

printNum()

output
      1
    1 2
  1 2 3
1 2 3 4
Copy after login
function printNum(){
 for(let i=1; i<=4; i++){
     let finalOutput = '';
     for (let k=1; k<=4-i;k++){
         finalOutput += " "
     }
     for(let j=1; j<=i; j++){
         finalOutput += i
     }
     console.log(finalOutput)
 }   
}

printNum()

output
      1
    1 2
  1 2 3
1 2 3 4
Copy after login
function printNum(){
 for(let i=1; i<=4; i++){
     let finalOutput = '';
     for (let k=1; k<=4-i;k++){
         finalOutput += " "
     }
     for(let j=1; j<=i; j++){
         finalOutput += j + " "
     }
     console.log(finalOutput)
 }   
}

printNum()

output
   1
  1 2
 1 2 3
1 2 3 4
Copy after login
function printNum(){
 for(let i=1; i<=4; i++){
     let finalOutput = '';
     for (let k=1; k<=4-i;k++){
         finalOutput += " "
     }
     for(let j=1; j<=i; j++){
         finalOutput += i + " "
     }
     console.log(finalOutput)
 }   
}

printNum()

output
   1
  2 2
 3 3 3
4 4 4 4
Copy after login

The above is the detailed content of Number Patterns in Javascript. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!