11.6 Homework Assignment
Objective:
Students will apply their knowledge of JavaScript variables and console.log() to create a script that stores personal information in variables and displays the information in the console.
Task:
Write a JavaScript script that uses variables to store the following personal information:
Name
Age
Favorite Color
The script should then use
console.log()to display each piece of information in the browser's console.
Step-by-Step Instructions:
Create an HTML file (e.g.,
homework.html) and embed your JavaScript code within the<script>tag.Example Code:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Personal Information Script</title> </head> <body> <h1>Check the Console for Personal Information</h1> <script> // Declare variables to store personal information let name = "Baitik Baatyr"; let age = 50; let favoriteColor = "Blue"; // Use console.log() to display the information console.log("Name: " + name); // Outputs: Name: Baitik Baatyr console.log("Age: " + age); // Outputs: Age: 50 console.log("Favorite Color: " + favoriteColor); // Outputs: Favorite Color: Blue </script> </body> </html>Open the file in a browser:
Open the HTML file in a browser (Chrome, Firefox, etc.).
Use Developer Tools (F12 or right-click and select Inspect) to view the console output.
Modify the variables:
Change the values of the
name,age, andfavoriteColorvariables to reflect your own personal information.Ensure the modified values are correctly displayed in the console.
Challenge:
Add an additional variable for hobbies (as an array) and log it to the console:
let hobbies = ["Reading", "Coding", "Hiking", "Shooting"]; console.log("Hobbies: " + hobbies.join(", ")); // Outputs: Hobbies: Reading, Coding, Hiking
Expected Output in the Console:
Name: Baitik Baatyr
Age: 50
Favorite Color: Blue
Hobbies: Reading, Coding, Hiking, ShootingHomework Submission:
Save your HTML file and submit it to the instructor for review.
Make sure that all variables and console outputs are correctly displayed and formatted.
Expected Outcome:
By completing this homework, students will reinforce their understanding of:
Declaring and using variables in JavaScript.
Displaying information using
console.log().Storing and manipulating simple and complex data (such as arrays) in variables.
Last updated