Skip to Content
Lab 2

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 or const 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

  1. Create a JavaScript File:
    Create a file named personalInfo.js in your code editor.

  2. 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 or false).
  3. 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.
  4. 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.
  5. Output:

    • Use console.log() to display the formatted message.

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 the personalInfo.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

CriteriaPointsDescription
Variable Declarations8 ptsCode includes at least four variables (name, age, height, isStudent) with appropriate data types.
Type Casting & Data Conversion6 ptsDemonstrates proper type conversion (e.g., using String(age) or template literals) to correctly combine different data types in the output.
Console Output & Formatting8 ptsUses console.log() to print a formatted message that accurately includes all variable values.
Use of Comments4 ptsCode includes a header comment describing the script’s purpose and at least two inline comments explaining key logic.
Code Quality & Organization4 ptsCode is clean, properly indented, and uses descriptive variable names; follows best practices.

Total Points: 30 points

Note

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.