From f9e1a43dd96968fd69d76e66c528242876e60c48 Mon Sep 17 00:00:00 2001 From: James Kollilon Barclay III Date: Tue, 31 Mar 2026 11:27:31 -0400 Subject: [PATCH 1/2] "JKB Java-Script intro 2" --- js-data-types-lab/lab.js | 176 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 js-data-types-lab/lab.js diff --git a/js-data-types-lab/lab.js b/js-data-types-lab/lab.js new file mode 100644 index 0000000..cfd358e --- /dev/null +++ b/js-data-types-lab/lab.js @@ -0,0 +1,176 @@ +// ===================== +// Part 1: Strings +// ===================== + +let fullName = "James Barclay"; + +console.log("Length:", fullName.length); +console.log("Uppercase:", fullName.toUpperCase()); +console.log("Includes Barclay:", fullName.includes("Barclay")); +console.log("First Name:", fullName.slice(0, 5)); + +// Mini Challenge +function greet(name) { + return "HELLO, " + name.toUpperCase() + "!"; +} + +console.log(greet("James Barclay")); + +// Check for Understanding: +// 1. .length returns number of characters in a string +// 2. .includes() returns true or false +// 3. .slice() extracts part of a string + + +// ===================== +// Part 2: Numbers +// ===================== + +let num1 = 10; +let num2 = 3; + +console.log("Add:", num1 + num2); +console.log("Subtract:", num1 - num2); +console.log("Multiply:", num1 * num2); +console.log("Divide:", num1 / num2); +console.log("Remainder:", num1 % num2); + +console.log("Rounded:", Math.round(3.7)); +console.log("Random 1-10:", Math.floor(Math.random() * 10) + 1); + +// Mini Challenge +function evenOrOdd(num) { + if (num % 2 === 0) { + return "Even"; + } else { + return "Odd"; + } +} + +console.log(evenOrOdd(7)); + +// Check for Understanding: +// 1. % gives remainder +// 2. Math.random() returns a number between 0 and 1 +// 3. Math.floor() rounds down to the nearest + + +// ===================== +// Part 3: Arrays +// ===================== + +let students = ["A", "B", "C", "D"]; + +// Print all students +for (let i = 0; i < students.length; i++) { + console.log(students[i]); +} + +// Add new student +students.push("E"); + +// Remove last student +students.pop(); + +// Total number +console.log("Total Students:", students.length); + +// Mini Challenge +function sumArray(arr) { + let sum = 0; + for (let i = 0; i < arr.length; i++) { + sum += arr[i]; + } + return sum; +} + +console.log("Sum:", sumArray([1, 2, 3, 4])); + +// Check for Understanding: +// 1. Use index like arr[0] +// 2. .push() adds to end +// 3. Loops help go through each item + + +// ===================== +// Part 4: Objects +// ===================== + +let car = { + brand: "Ford", + model: "Taurus", + year: 2000 +}; + +// Print properties +console.log(car.brand); +console.log(car.model); +console.log(car.year); + +// Update year +car.year = 2000; + +// Add new property +car.color = "Silver"; + +// Loop through object +for (let key in car) { + console.log(key, car[key]); +} + +// Mini Challenge +function describePerson(person) { + return person.name + " is " + person.age + " years old"; +} + +console.log(describePerson({ name: "James Barclay", age: 34 })); + +// Check for Understanding: +// 1. Key-value = property: value +// 2. Use dot or bracket notation +// 3. Use objects for structured data + + +// ===================== +// Final Challenge +// ===================== + +let student = { + name: "James Barclay", + scores: [80, 90, 75, 100] +}; + +function calculateAverage(scores) { + let total = 0; + + for (let i = 0; i < scores.length; i++) { + total += scores[i]; + } + + return total / scores.length; +} + +function getGrade(avg) { + if (avg >= 90) return "A"; + else if (avg >= 80) return "B"; + else if (avg >= 70) return "C"; + else if (avg >= 60) return "D"; + else return "F"; +} + +let average = calculateAverage(student.scores); +let grade = getGrade(average); + +console.log("Name:", student.name); +console.log("Average:", average); +console.log("Grade:", grade); + + +// ===================== +// Reflection +// ===================== + +// 1. Easiest: Strings because methods are simple and clear +// 2. Most confusing: Objects loops (for...in) +// 3. Arrays store lists, objects store labeled data +// 4. Arrays = lists (scores), Objects = structured data (user profiles) \ No newline at end of file From bb9182b26be64ba938f1eeffb7cbe841443b894c Mon Sep 17 00:00:00 2001 From: James Kollilon Barclay III Date: Tue, 31 Mar 2026 11:50:16 -0400 Subject: [PATCH 2/2] finished --- js-data-types-lab/lab.js | 65 +++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/js-data-types-lab/lab.js b/js-data-types-lab/lab.js index cfd358e..11387ab 100644 --- a/js-data-types-lab/lab.js +++ b/js-data-types-lab/lab.js @@ -1,6 +1,6 @@ -// ===================== -// Part 1: Strings -// ===================== + +// Part 1: strings + let fullName = "James Barclay"; @@ -9,7 +9,7 @@ console.log("Uppercase:", fullName.toUpperCase()); console.log("Includes Barclay:", fullName.includes("Barclay")); console.log("First Name:", fullName.slice(0, 5)); -// Mini Challenge +// mini challenge function greet(name) { return "HELLO, " + name.toUpperCase() + "!"; } @@ -17,14 +17,13 @@ function greet(name) { console.log(greet("James Barclay")); // Check for Understanding: -// 1. .length returns number of characters in a string -// 2. .includes() returns true or false -// 3. .slice() extracts part of a string +// 1. .length basically returns number of characters in a string +// 2. .includes() just returns true or false +// 3. .slice() just extracts part of a string + +// Part 2: numbers -// ===================== -// Part 2: Numbers -// ===================== let num1 = 10; let num2 = 3; @@ -38,7 +37,7 @@ console.log("Remainder:", num1 % num2); console.log("Rounded:", Math.round(3.7)); console.log("Random 1-10:", Math.floor(Math.random() * 10) + 1); -// Mini Challenge +// mini challenge function evenOrOdd(num) { if (num % 2 === 0) { return "Even"; @@ -55,27 +54,26 @@ console.log(evenOrOdd(7)); // 3. Math.floor() rounds down to the nearest -// ===================== -// Part 3: Arrays -// ===================== + +// Part 3: arrays let students = ["A", "B", "C", "D"]; -// Print all students +// print all students for (let i = 0; i < students.length; i++) { console.log(students[i]); } -// Add new student +// add new student students.push("E"); -// Remove last student +// remove last student students.pop(); -// Total number +// total number console.log("Total Students:", students.length); -// Mini Challenge + function sumArray(arr) { let sum = 0; for (let i = 0; i < arr.length; i++) { @@ -92,9 +90,9 @@ console.log("Sum:", sumArray([1, 2, 3, 4])); // 3. Loops help go through each item -// ===================== -// Part 4: Objects -// ===================== + +// Part 4: objects + let car = { brand: "Ford", @@ -102,38 +100,36 @@ let car = { year: 2000 }; -// Print properties +// print properties console.log(car.brand); console.log(car.model); console.log(car.year); -// Update year +// update year car.year = 2000; -// Add new property +// add color car.color = "Silver"; -// Loop through object +// looping through the object for (let key in car) { console.log(key, car[key]); } -// Mini Challenge + function describePerson(person) { return person.name + " is " + person.age + " years old"; } console.log(describePerson({ name: "James Barclay", age: 34 })); -// Check for Understanding: -// 1. Key-value = property: value -// 2. Use dot or bracket notation +//check understanding +// 1. Key-value is basically property: value +// 2. Use dot/bracket notation // 3. Use objects for structured data -// ===================== -// Final Challenge -// ===================== + let student = { name: "James Barclay", @@ -166,9 +162,8 @@ console.log("Average:", average); console.log("Grade:", grade); -// ===================== + // Reflection -// ===================== // 1. Easiest: Strings because methods are simple and clear // 2. Most confusing: Objects loops (for...in)