Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting much output from the number of user input in Javascript

In Python I use "for x in range(j)" and j is defined from user input, for example

j = int(input())
for x in range(j)
print(j)

if I input j as 3, the output will be

3
3
3

My question is, how do i do it with javascript?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried to do it with array, etc. Nothing seems to work, sorry im really new at coding and need to learn 2 programming language for my college

>Solution :

You can do it with prompt function

const printData = () =>{

  let num = prompt("Please input a number", "3") // second parameter is the default value
  if(isNaN(num)){
    console.error(`${num} is an invalid number`)
    return
  }

 for(let i=0;i<num;i++){
    console.log(num)
  }
}

printData()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading