22.9k views
5 votes
Write a JavaScript function named countUp( ), which displays 1 to 10.

2 Answers

3 votes

Answer:

class countUp {

constructor() {

for (let i = 1; i <= 10; ++i) {

console.log(i);

}

}

}

const count = new countUp();

Step-by-step explanation:

To solve the problem we create a class called countUp with the main method called constructor, inside constructor we have a for loop that iterates from one to ten increasing the variable i by one after each iteration, inside the for is a console function to print the numbers from one to ten one at a time. Note that for this program to work we need to instantiate the class countUp using the variable count.

Write a JavaScript function named countUp( ), which displays 1 to 10.-example-1
User Reza Afzalan
by
6.5k points
1 vote

Answer:

Following are the code in javascript

<html>

<body>

<button onclick="countUp()">Try it</button>

<script>

function countUp()

{

var i;

for (i = 0; i <=10; i++)

{

document.write(i) ;

document.write("<br>") ;

}

}

</script>

</body>

</html>

Step-by-step explanation:

In this program when we click on button " Try it " it call the javascript function countUp( ) which display the value from 1 to 10.

output

1

2

3

4

5

6

7

8

9

10

User Tonald Drump
by
5.0k points