Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Russels submission for 01-basics #18

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 28 additions & 1 deletion src/01-0-basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,79 @@
* Task 1: String Manipulation
*/

// 1. Define three string variables firstName, middleName, and lastName.
// In your main script file (e.g., app.js)
var firstName = "Russel";
var middleName = "Shalom";
var lastName = "Davis";


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

}

/**
* Task 2: Data Types
*/

// 1. Declare a variable named age and assign it a number.
var age = 23;

// 2. Declare a variable named isStudent and assign it a boolean value.
var isStudent = true
// 3. Declare a variable named courses and assign it an array containing three string values representing courses e.g. "Math", "Science", "History".
var courses = ["Math", "Science", "History"];

// 4. Declare a function named logVariableTypes that takes no arguments.
function logVariableTypes() {
// 5. Print the type of each variable using the typeof operator.
console.log(typeof age);
console.log(typeof isStudent);
console.log(typeof courses);
}


/**
* Task 3: Variables Declaration
*/

// 1. Using var, declare a variable named school and assign it a value of "Hogwarts".
var school = "Hogwarts";
// 2. Using let, declare a variable named subject and assign it a value of "Potions".
let subject = "Potions";
// 3. Using const, declare a variable named professor and assign it a value of "Snape".
const professor = "Snape";

/**
* Task 4: Basic Operators
*/

// 1. Declare two variables x and y with values 5 and 10 respectively.
const x = 5
const y = 10

function logAddition() {
// 2. Log the sum of x and y.
console.log(x + y);
}
function logSubtraction() {
// 3. Log the x subtracted from y
console.log(y - x);
}

function logMultiplication() {
// 4. Log the product of x and y.
console.log (x * y);

}

function logDivision() {
// 5. Log the quotient when x is divided by y.
console.log (x / y);
}

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

function logResults() {
// 3. Log both result values in your JavaScript environment and check your answers.
console.log(3 + 4 * 5);
console.log((3 + 4) * 5);
}
60 changes: 50 additions & 10 deletions src/01-1-basics.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
/**
* Task 6: Control Structures - Conditional Statements
*/
// /**
// * Task 6: Control Structures - Conditional Statements
// */

// Define a variable named studentGrade that is of type number.
// // Define a variable named studentGrade that is of type number.
let studentGrade = 70;

function gradeCommentary() {
// 1. If studentGrade is above or equal to 90, log "Excellent work!".
if (studentGrade >= 90) {
console.log("Excellent work!");
}
// 2. If studentGrade is between 80 and 89 (inclusive), log "Good job!".
else if (studentGrade >= 80 && studentGrade <= 89) {
console.log("Good job!");
}
// 3. If studentGrade is between 70 and 79 (inclusive), log "You passed.".
else if (studentGrade >= 70 && studentGrade <= 79) {
console.log("You passed.");
}
// 4. If studentGrade is below 70, log "Needs improvement.".
else {
console.log("Needs improvement.");
}
}

/**
Expand All @@ -17,13 +30,21 @@ function gradeCommentary() {

function logNumbers() {
// 1. Log numbers from 1 to 10 using a for loop.
for (let i = 1; i <= 10; i++) {
console.log(i);
}
}

function countByTwos() {
// 2. Using a while loop, log even numbers from 2 to 20.
let i = 2;
while (i <= 20) {
console.log(i);
i += 2;
}
}

function triangle() {
function triangle() {
// 3. Using loops, output a traingle of '#' characters
/*
#
Expand All @@ -34,21 +55,34 @@ function triangle() {
######
#######
*/
let i = 1;
while (i <= 7){
console.log("#".repeat(i));
i++;
}
}

/**
* Task 8: More on Functions
*/
// * Task 8: More on Functions
// */

// 1. Declare a function named calculateArea that takes two arguments: length and width. It should return the area of a rectangle.
// Declare the function named calculateArea
function calculateArea(length, width) {
// Your code here
// Return the calculated area of the rectangle
if(length * width < 0){
return NaN;

}
return length * width;
}



// 2. Declare a function expression named greetPerson that takes a name as an argument and logs a greeting.
var greetPerson = function (name) {
// Your code here
};
console.log("Hello, "+ name + "!");
}

/**
* Task 9: Objects and Properties
Expand All @@ -57,19 +91,25 @@ var greetPerson = function (name) {
// 1. Declare an object named book with properties: title, author, and year.
var book = {
// Your properties here
title: "Harry Potter",
author: "J.K Rowling",
year: 1997,
};

// 2. Log the book's title.
function logBookTitle() {
// Your code here
console.log(book.title)
}

// 3. Update the book's year to the current year.
function updateYear() {
// Your code here
book.year = 2024;
}

// 4. Add a new property to the book: genre, and assign it a value.
function addGenre() {
// Your code here
book.genre = "Fantasy";
}
17 changes: 17 additions & 0 deletions src/01-2-basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@
function generateBandName(clothingColor, lastFoodEaten) {
// Your code here
// Initialize bandName to an empty string
let bandName = "";
// Function to capitalize the first letter of each word
function capitalizeFirstLetter (word) {
if (typeof word === "number") {
return word.toString();
}
if (typeof word !== "string" || word === null) {
return "";
}
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();

}
// Construct the band name
bandName =
"The " +
capitalizeFirstLetter(clothingColor) +
" " +
capitalizeFirstLetter(lastFoodEaten);
return bandName
}
Loading