This HTML file named For While Loops includes a script designed to demonstrate various array operations, the usage of control structures like loops and conditionals, and the process of handling user inputs through prompts. It provides practical examples of manipulating arrays, employing for and while loops, and implementing simple interactive predictions based on user input.
- Demonstrates how to find the index of an element, move elements within an array, and remove elements from an array.
- For Loop: Implements a for loop to count from 1 to 10, appending "Mississippi" to each number.
- Even Number Logger: Utilizes a for loop to iterate through an array of numbers, logging only the even numbers to the console.
- Sum Odd Numbers: A while loop is used to sum odd numbers from 1 to 10.
- Predictions: Collects user predictions for game winners and their scores through browser prompts.
- Results Comparison: Compares user predictions against simulated results to calculate and display the user's accuracy in predictions.
- Language: HTML & JavaScript
- External Libraries: None required.
- Browser Compatibility: Compatible with modern web browsers. Outputs are logged to the console, and inputs are collected via prompts.
- Open the HTML file in a web browser to execute the script.
- When prompted, enter your predictions for the winners of the games and their scores. This input phase will occur twice, corresponding to two hypothetical matchups.
- The script logs operations performed on arrays, iterations of loops, and the comparison of user predictions against simulated outcomes. Check the console of your web browser to view these logs.
- The outcomes of the games are simulated randomly within the script, and the user's score is calculated based on these simulations.
- The script uses the
promptfunction to collect user input, which may be blocked or require permission in some browser settings. - For full interaction with the prompts and to view console outputs, ensure your browser's JavaScript console is accessible.
This script is primarily for educational purposes, designed to illustrate JavaScript programming concepts such as array manipulation, control structures (loops and conditionals), and basic user interaction through the web browser. It is suitable for learners looking to explore these concepts in a practical, hands-on manner.