Skip to content

Commit 9688903

Browse files
committed
test
test all
1 parent 955a910 commit 9688903

File tree

4 files changed

+97
-13
lines changed

4 files changed

+97
-13
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/01-0-basics.js

+28-1
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,79 @@
22
* Task 1: String Manipulation
33
*/
44

5-
// 1. Define three string variables firstName, middleName, and lastName.
5+
// In your main script file (e.g., app.js)
6+
var firstName = "Russel";
7+
var middleName = "Shalom";
8+
var lastName = "Davis";
9+
610

711
// 2. Declare a function named logFullName that takes no arguments.
812
function logFullName() {
913
// 3. Using template literals, create another variable fullName that combines all three names.
14+
const fullName = `${firstName} ${middleName} ${lastName}`
1015
// 4. Print the fullName to the console.
16+
console.log(fullName);
17+
1118
}
1219

1320
/**
1421
* Task 2: Data Types
1522
*/
1623

1724
// 1. Declare a variable named age and assign it a number.
25+
var age = 23;
26+
1827
// 2. Declare a variable named isStudent and assign it a boolean value.
28+
var isStudent = true
1929
// 3. Declare a variable named courses and assign it an array containing three string values representing courses e.g. "Math", "Science", "History".
30+
var courses = ["Math", "Science", "History"];
2031

2132
// 4. Declare a function named logVariableTypes that takes no arguments.
2233
function logVariableTypes() {
2334
// 5. Print the type of each variable using the typeof operator.
35+
console.log(typeof age);
36+
console.log(typeof isStudent);
37+
console.log(typeof courses);
2438
}
2539

40+
2641
/**
2742
* Task 3: Variables Declaration
2843
*/
2944

3045
// 1. Using var, declare a variable named school and assign it a value of "Hogwarts".
46+
var school = "Hogwarts";
3147
// 2. Using let, declare a variable named subject and assign it a value of "Potions".
48+
let subject = "Potions";
3249
// 3. Using const, declare a variable named professor and assign it a value of "Snape".
50+
const professor = "Snape";
3351

3452
/**
3553
* Task 4: Basic Operators
3654
*/
3755

3856
// 1. Declare two variables x and y with values 5 and 10 respectively.
57+
const x = 5
58+
const y = 10
3959

4060
function logAddition() {
4161
// 2. Log the sum of x and y.
62+
console.log(x + y);
4263
}
4364
function logSubtraction() {
4465
// 3. Log the x subtracted from y
66+
console.log(y - x);
4567
}
4668

4769
function logMultiplication() {
4870
// 4. Log the product of x and y.
71+
console.log (x * y);
72+
4973
}
5074

5175
function logDivision() {
5276
// 5. Log the quotient when x is divided by y.
77+
console.log (x / y);
5378
}
5479

5580
/**
@@ -64,4 +89,6 @@ let result2 = (3 + 4) * 5;
6489

6590
function logResults() {
6691
// 3. Log both result values in your JavaScript environment and check your answers.
92+
console.log(3 + 4 * 5);
93+
console.log((3 + 4) * 5);
6794
}

src/01-1-basics.js

+50-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1-
/**
2-
* Task 6: Control Structures - Conditional Statements
3-
*/
1+
// /**
2+
// * Task 6: Control Structures - Conditional Statements
3+
// */
44

5-
// Define a variable named studentGrade that is of type number.
5+
// // Define a variable named studentGrade that is of type number.
6+
let studentGrade = 70;
67

78
function gradeCommentary() {
89
// 1. If studentGrade is above or equal to 90, log "Excellent work!".
10+
if (studentGrade >= 90) {
11+
console.log("Excellent work!");
12+
}
913
// 2. If studentGrade is between 80 and 89 (inclusive), log "Good job!".
14+
else if (studentGrade >= 80 && studentGrade <= 89) {
15+
console.log("Good job!");
16+
}
1017
// 3. If studentGrade is between 70 and 79 (inclusive), log "You passed.".
18+
else if (studentGrade >= 70 && studentGrade <= 79) {
19+
console.log("You passed.");
20+
}
1121
// 4. If studentGrade is below 70, log "Needs improvement.".
22+
else {
23+
console.log("Needs improvement.");
24+
}
1225
}
1326

1427
/**
@@ -17,13 +30,21 @@ function gradeCommentary() {
1730

1831
function logNumbers() {
1932
// 1. Log numbers from 1 to 10 using a for loop.
33+
for (let i = 1; i <= 10; i++) {
34+
console.log(i);
35+
}
2036
}
2137

2238
function countByTwos() {
2339
// 2. Using a while loop, log even numbers from 2 to 20.
40+
let i = 2;
41+
while (i <= 20) {
42+
console.log(i);
43+
i += 2;
44+
}
2445
}
2546

26-
function triangle() {
47+
function triangle() {
2748
// 3. Using loops, output a traingle of '#' characters
2849
/*
2950
#
@@ -34,21 +55,34 @@ function triangle() {
3455
######
3556
#######
3657
*/
58+
let i = 1;
59+
while (i <= 7){
60+
console.log("#".repeat(i));
61+
i++;
62+
}
3763
}
3864

3965
/**
40-
* Task 8: More on Functions
41-
*/
66+
// * Task 8: More on Functions
67+
// */
4268

43-
// 1. Declare a function named calculateArea that takes two arguments: length and width. It should return the area of a rectangle.
69+
// Declare the function named calculateArea
4470
function calculateArea(length, width) {
45-
// Your code here
71+
// Return the calculated area of the rectangle
72+
if(length * width < 0){
73+
return NaN;
74+
75+
}
76+
return length * width;
4677
}
4778

79+
80+
4881
// 2. Declare a function expression named greetPerson that takes a name as an argument and logs a greeting.
4982
var greetPerson = function (name) {
5083
// Your code here
51-
};
84+
console.log("Hello, "+ name + "!");
85+
}
5286

5387
/**
5488
* Task 9: Objects and Properties
@@ -57,19 +91,25 @@ var greetPerson = function (name) {
5791
// 1. Declare an object named book with properties: title, author, and year.
5892
var book = {
5993
// Your properties here
94+
title: "Harry Potter",
95+
author: "J.K Rowling",
96+
year: 1997,
6097
};
6198

6299
// 2. Log the book's title.
63100
function logBookTitle() {
64101
// Your code here
102+
console.log(book.title)
65103
}
66104

67105
// 3. Update the book's year to the current year.
68106
function updateYear() {
69107
// Your code here
108+
book.year = 2024;
70109
}
71110

72111
// 4. Add a new property to the book: genre, and assign it a value.
73112
function addGenre() {
74113
// Your code here
114+
book.genre = "Fantasy";
75115
}

src/01-2-basics.js

+17
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,23 @@
1111
function generateBandName(clothingColor, lastFoodEaten) {
1212
// Your code here
1313
// Initialize bandName to an empty string
14+
let bandName = "";
1415
// Function to capitalize the first letter of each word
16+
function capitalizeFirstLetter (word) {
17+
if (typeof word === "number") {
18+
return word.toString();
19+
}
20+
if (typeof word !== "string" || word === null) {
21+
return "";
22+
}
23+
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
24+
25+
}
1526
// Construct the band name
27+
bandName =
28+
"The " +
29+
capitalizeFirstLetter(clothingColor) +
30+
" " +
31+
capitalizeFirstLetter(lastFoodEaten);
32+
return bandName
1633
}

0 commit comments

Comments
 (0)