Topic: Loop
3. Create a loop that rolls a six sided die 50 times. Using an array, count how many times each side is rolled. Display the results.
Variation:
Create a loop that rolls a 20 sided die 500 times. Using an array, count how many times each side is rolled. Display the results.
See more
45. Create a brute force algorithm that breaks into a 3 digit pad lock.
See more
42. Create a 0 player rock paper scissors game. Why 0 players? Make the computer play against itself. Run the process 3 times.
See more
41. Create a for loop to run 35 times, but display the counter variable in front of the numbers. Generate 3 random numbers 1-25 in each iteration of the for loop.
See more
40. Create a while loop that generates 100 random numbers. Only run the loop 50 times.
See more
38. Create a form that collects 3 numbers from the user in a form. Use GET to collect the variables. Use the first and second numbers with the rand() function to create random numbers. Use a loop to create the third number's worth of random numbers.
See more
34. Create a number guessing name. The random number to guess should be between 1 and 100. Keep all the guesses made in an array. Count the number of guesses. As the user guesses, tell the user if they are too low or are too high.
See more
31. Collect 40 numbers into an array. Using 10 rounds of 4 numbers, complete the following on the 4 numbers. Add the first and second together, then divide by the third and multiple by the fourth. Show each formula with its answer showing like this: (first + second) / third * fourth = answer
See more
20. Collect 10 numbers from the user. Report back if the numbers are odd or even. Then tell the count of how many each of odd and even numbers.
See more
10. Fill an array with random numbers. Display the array. Output the average of all the numbers.
See more
16. Write a script that asks the user for a number of elements. Then ask the user if they would like a ol or ul and generate the HTML to create the list with the specified number of elements.
See more
14. Find all the prime numbers between 1 and 100. Use a loop to find them.
See more
9. Fill an array of random numbers 1-100 of 25. Sort the array from smallest to largest numbers
See more
8. Design a program that outputs 21 random numbers between 1 -1000. Display the numbers in an HTML table that is 3 columns wide and as many rows as needed. Your table borders need to be visible.
Modifications
- Modify the program to allow the user to set the column number of the table.
If random numbers do not complete the last row then fill in the empty spaces with cells with non-breaking spaces
- Modify the program to all the user to set the number of random numbers
- modify the program to allow the user to set the ending range
- modify the program to allow the user to set the starting range
See more
5. In a while loop, get numbers from the user until "end" is entered. Add the numbers together and display the sum.
See more
4. Write a script that adds the odd numbers from 7-37. Display the total.
See more
2. Put numbers 15 to 1 in array. Display the number as well as the squared and cubed value.
See more