146k views
0 votes
Write a function that prints the first 10 integers on the

console starting from the number 1 using the JavaScript for
loop.

1 Answer

4 votes

Final answer:

To print the first 10 integers starting from 1, you can write a JavaScript function that uses a for loop to iterate and log each number to the console.

Step-by-step explanation:

To print the first 10 integers starting from 1 on the console using a JavaScript for loop, you can write a function like this:

function printFirstTenIntegers() {
for(let i = 1; i <= 10; i++) {
console.log(i);
}
}

printFirstTenIntegers();

The function printFirstTenIntegers uses a for loop to iterate from 1 to 10, and for each number, it uses console.log to print the number to the console. This pattern is common for introductory JavaScript exercises focused on loop and function basics.

User Stsloth
by
7.7k points