193k views
3 votes
Write a JavaScript program that uses a function and a loop to print a list of the days of the week. Use JavaScript.

User Dasheddot
by
5.2k points

1 Answer

3 votes

Answer:

<html>

<body>

<script>

days1(); // calling function days1()

function days1() // function days1

{

var week = ["sunday ", "monday ", "tuesday "," wednesday"," thursday",

"friday"," saturday"];

var i;

for (i=0;i<7;i++) // iterating over the loop

{

document.write(" The number of days in a week :" +</br>);

document.write( week[i] + "</br>" ); // print the number of days

}

}

</script>

</body>

</html>

Output:

The number of days in a week :

sunday

monday

tuesday

wednesday

thursday

friday

saturday

Step-by-step explanation:

In this program, we create a function days1().In this function, we declared an array i.e " week " which will store the list of the days of the week. After that, we iterate the for loop and prints a list of the days of the week.

User John Ashmore
by
5.2k points