settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Print Numbers from N to 1

+10 votes

You are given a number N. Create a program that loops through all of the numbers from N to 1 and prints them. N will always be positive.

Examples:

Input

Output

 

Input

Output

5

5

4

3

2

1

 

2

2

1

 

asked in JavaScript category by user matthew44

1 Answer

+2 votes
 
Best answer

Here's the answer:

function fromNtoOne(args) {
  let input = args[0];
  for (var i = input; i >= 1; i--) {
    console.log(i);
  }
}
answered by user mitko
edited by user golearnweb
...