Test comp sci flashcard
🔹 Step-by-Step Fill-in-the-Blank Answers
Step 1: Create Inputs
Use the <form> tag inside the <body> of your HTML page
Form inputs can include:
text
number
select
submit
Every input must have a unique id
IDs allow inputs to be accessed in JavaScript
🧠 Common blank:
Each input must be given a unique id
Step 2: Create Outputs
Outputs are created using <div> tags
Each output <div> must have a unique id
Output <div> elements are updated using JavaScript
🧠 Common blank:
Outputs are created using <div> tags
Step 3: Access Output Elements (Global Scope)
Output <div> elements are stored in variables
This must be done in the global scope
Global scope means outside of any functions
🧠 Common blank:
This must be done in the global scope
Step 4: Set Up the Submit Button
Access the submit button in the global scope
Use addEventListener
The event triggers the main function
The function runs when the button is clicked
🧠 Common blank:
Use addEventListener to run the main function
Step 5: Get User Input
Create a main function
Retrieve values entered by the user
Use .value to get input data
Prevent the default form behavior using
e.preventDefault()
🧠 VERY common blank:
Prevent the default form behavior by e.preventDefault()
Step 6: Process the Data
Create a function that:
Uses parameters
Takes in user input
Processes the data
Returns a result
🧠 Common blank:
Create a function that accepts user input as parameters
Step 7: Display the Output
Call the function with arguments
Update output <div> elements using innerHTML
Display the returned value or updated variable
🧠 VERY common blank:
Update the output <div> using innerHTML
🔹 Key Reminders (Almost Guaranteed Quiz Items)
IDs must be unique
Flow of a program:
Inputs → Processing → OutputFunctions should have a clear purpose
Code should be organized and readable