In this lab, you will explore how JavaScript stores and manipulates data using:
- Strings (text)
- Numbers (math)
- Arrays (lists)
- Objects (structured data)
This is a guided walkthrough lab, meaning:
- You will read β try β build β reflect
- Each section builds on the previous one
- You will combine everything at the end
By the end of this lab, you will be able to:
- Manipulate strings using built-in methods
- Perform mathematical operations with numbers
- Store and loop through data using arrays
- Create and access objects with key-value pairs
- Combine all concepts into real-world scenarios
mkdir js-data-types-lab
cd js-data-types-lab
touch lab.js
code .
node lab.jsjs-data-types-lab/
β
βββ lab.js
A string is text wrapped in quotes.
let name = "Coreye";let message = "hello world";
message.length // length of string
message.toUpperCase() // HELLO WORLD
message.toLowerCase() // hello world
message.includes("world") // true
message.slice(0, 5) // helloCreate a variable:
let fullName = "your name here";- Print the length of the string
- Convert it to uppercase
- Check if it includes your last name
- Slice out your first name only
Create a function that:
- Accepts a name
- Returns:
"Hello, NAME!"(all caps)
- What does
.lengthdo? - What does
.includes()return? - What does
.slice()do?
A number represents numeric values.
let age = 25;
let price = 19.99;let a = 10;
let b = 3;
a + b // addition
a - b // subtraction
a * b // multiplication
a / b // division
a % b // remainderMath.round(4.6) // 5
Math.floor(4.9) // 4
Math.ceil(4.1) // 5
Math.random() // random number 0β1Create variables:
let num1 = 10;
let num2 = 3;- Add, subtract, multiply, divide
- Find remainder
- Round a decimal number
- Generate a random number between 1β10
Create a function that:
-
Accepts a number
-
Returns:
- "Even" if even
- "Odd" if odd
- What does
%do? - What does
Math.random()return? - When would you use
Math.floor()?
An array is a list of values.
let fruits = ["apple", "banana", "orange"];fruits[0] // apple
fruits[1] // bananafruits.push("grape") // add to end
fruits.pop() // remove last
fruits.length // number of itemsfor (let i = 0; i < fruits.length; i++) {
console.log(fruits[i]);
}Create an array:
let students = ["A", "B", "C", "D"];- Print all students
- Add a new student
- Remove the last student
- Print total number of students
Create a function that:
- Accepts an array of numbers
- Returns the sum of all numbers
- How do you access an array element?
- What does
.push()do? - Why do we use loops with arrays?
An object stores data as key-value pairs.
let person = {
name: "Coreye",
age: 25,
isStudent: true
};person.name
person["age"]person.age = 26;for (let key in person) {
console.log(key, person[key]);
}Create an object:
let car = {
brand: "Toyota",
model: "Camry",
year: 2020
};- Print each property
- Update the year
- Add a new property (color)
- Loop through the object
Create a function that:
- Accepts a person object
- Returns a sentence like:
"Name is AGE years old"
- What is a key-value pair?
- How do you access object data?
- When would you use an object instead of an array?
Create:
A student object:
{
name: "Student Name",
scores: [80, 90, 75, 100]
}Build a program that:
-
Loops through scores
-
Calculates average
-
Determines grade:
- A, B, C, D, F
-
Prints:
Name: John
Average: 86
Grade: B
-
Must use:
- arrays (scores)
- object (student)
- loop (iterate scores)
- function (calculate average)
- conditionals (grade logic)
- β
Completed
lab.js - β All 4 sections completed
- β Mini challenges completed
- β Final challenge completed
- β Reflection questions
| Category | Points |
|---|---|
| Strings | 15 pts |
| Numbers | 15 pts |
| Arrays | 20 pts |
| Objects | 20 pts |
| Final Challenge | 20 pts |
| Code Quality | 5 pts |
| Reflection | 5 pts |
At the bottom of your file, answer:
- Which data type felt easiest?
- Which one was most confusing?
- How do arrays and objects differ?
- When would you use each in real applications?
- Test everything with
console.log() - Break problems into steps
- Donβt try to do everything at once
- If stuck β simplify