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

Karol's submission for 01-basics #19

Open
wants to merge 3 commits 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
Binary file modified .DS_Store
Binary file not shown.
16 changes: 8 additions & 8 deletions package-lock.json

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

24 changes: 24 additions & 0 deletions src/01-0-basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,75 @@
*/

// 1. Define three string variables firstName, middleName, and lastName.
var firstName = "Karol"
var middleName = "Olek"
var lastName = "Bledowski"

// 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.
var 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.

var x = 5
var 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 +86,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)
}
40 changes: 39 additions & 1 deletion src/01-1-basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,46 @@
*/

// 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.".
// 4. If studentGrade is below 70, log "Needs improvement.".
else if (studentGrade >= 70 && studentGrade <=79 ){
console.log("You passed.")
}
// 4. If studentGrade is below 70, log "Needs improvement.".
else {
console.log("Needs improvement.")
}
}


/**
* Task 7: Control Structures - Loops
*/

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() {
Expand All @@ -34,6 +56,11 @@ function triangle() {
######
#######
*/
let i = 1
while (i <= 7) {
console.log("#".repeat(i))
i++
}
}

/**
Expand All @@ -42,12 +69,17 @@ function triangle() {

// 1. Declare a function named calculateArea that takes two arguments: length and width. It should return the area of a rectangle.
function calculateArea(length, width) {
if (length * width < 0) {
return NaN
}
// Your code here
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 + "!");
};

/**
Expand All @@ -57,19 +89,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";
}
18 changes: 17 additions & 1 deletion src/01-2-basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@
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;
}
36 changes: 36 additions & 0 deletions src/webflow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

const clothingColor = document.querySelector("#clothing-color");
const food = document.querySelector("#food");
const bandNameText = document.querySelector("#band-name-text");
const form = document.querySelector("#band-name-form");

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;
}

form.addEventListener("submit", function (e) {
e.preventDefault();
e.stopPropagation();
const bandName = generateBandName(clothingColor.value, food.value);
console.log(bandName);
bandNameText.textContent = bandName;
});
Loading