Building a Personal Info Card in JavaScript
Overview and Objectives
In this lab, learners will practice declaring variables, working with different data types, performing type casting, and writing meaningful comments in JavaScript. By the end of this lab, you will be able to:
- Declare variables using
let
orconst
for various data types (string, number, boolean). - Perform type casting to convert between data types.
- Use string concatenation or template literals to output formatted messages.
- Include clear comments that document the code’s purpose and logic.
Tasks and Instructions
Task 1: Create the Personal Info Card Script
-
Create a JavaScript File:
Create a file namedpersonalInfo.js
in your code editor. -
Variable Declarations:
Declare the following variables:name
(string) – Your name.age
(number) – Your age.height
(number) – Your height in inches.isStudent
(boolean) – Indicate whether you are a learner (true
orfalse
).
-
Type Casting and Concatenation:
- Demonstrate type casting by converting your numeric age or height to a string when concatenating.
- Create a formatted message that includes all your variables. For example:
"Hello, my name is John. I am 25 years old, 180 cm tall, and it is true that I am a learner."
- You may use either string concatenation with the
+
operator or template literals.
-
Adding Comments:
- At the top of the file, include a comment explaining the purpose of the script.
- Add at least two additional inline comments that explain key parts of your code.
-
Output:
- Use
console.log()
to display the formatted message.
- Use
Task 2: Run Your Code
- Execution:
Run your code either in the browser’s developer console or using Node.js. - Verification:
Confirm that the console output shows the correct formatted message.
Submission Criteria
The following should be included within a GitHub repository, and submitted via Canvas:
- Files/Links:
Submit thepersonalInfo.js
file. - Output Evidence:
Provide a screenshot or a text log showing your code alongside the output in the console. - Error-Free Execution:
Ensure that your code executes without runtime errors.
Grading Rubric
Criteria | Points | Description |
---|---|---|
Variable Declarations | 8 pts | Code includes at least four variables (name, age, height, isStudent) with appropriate data types. |
Type Casting & Data Conversion | 6 pts | Demonstrates proper type conversion (e.g., using String(age) or template literals) to correctly combine different data types in the output. |
Console Output & Formatting | 8 pts | Uses console.log() to print a formatted message that accurately includes all variable values. |
Use of Comments | 4 pts | Code includes a header comment describing the script’s purpose and at least two inline comments explaining key logic. |
Code Quality & Organization | 4 pts | Code is clean, properly indented, and uses descriptive variable names; follows best practices. |
Total Points: 30 points
Partial credit will be awarded for submissions that demonstrate an understanding of the core concepts even if some elements are incomplete. For example, if the output is correct but one variable is missing or if there are fewer than the required comments, points will be deducted proportionally. Credit will be given for correct variable declarations, basic type casting, and clear code organization, even if minor syntax or formatting issues are present.