settingsAccountsettings
Menusettings

Q: Print Numbers from N to 1

+9 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

+1 vote
 
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
...