Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
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 added .DS_Store
Binary file not shown.
Binary file added exercises/.DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
console.log("Hello world");

console.log("Hello Mehreen");

console.log(123)

console.log("Mehreen 2022")
6 changes: 6 additions & 0 deletions exercises/C-variables/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Start by creating a variable `greeting`

console.log(greeting);

var greeting = "hello"

console.log("Hello")
console.log("Hello")
console.log("Hello")
8 changes: 8 additions & 0 deletions exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// Start by creating a variable `message`

var message = "This is a message in a";

var messageType = typeof message;

console.log(message);

console.log(messageType);


5 changes: 5 additions & 0 deletions exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Start by creating a variable `message`

var messageStart = "Hello, my name is ";
var name = "Mehreen";

var message = messageStart + name;

console.log(message);
14 changes: 12 additions & 2 deletions exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// Start by creating a variable `message`
var name = "Mehreen"

console.log(message);
nameLength = name.length

var statement = "My name is Mehreen and it is "

var statement2 = "characters long"

console.log(statement)

console.log(nameLength)

console.log(statement2)
8 changes: 6 additions & 2 deletions exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const name = " Daniel ";
const myName = " Mehreen ";

console.log(message);
let myName2 = myName.trim()



console.log(myName2);
8 changes: 7 additions & 1 deletion exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
let numberOfStudents = 40

let numberOfMentors = 10

console.log("Number of students is: " + numberOfStudents)

console.log("Number of mentors is: " + numberOfMentors)
13 changes: 13 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
var numberOfStudents = 15;
var numberOfMentors = 8;

percentageOfStudents = (numberOfStudents/23)*100

roughPercentageStudents = Math.round(percentageOfStudents)

percentageOfMentors = (numberOfMentors/23)*100

roughPercentageMentors = Math.round(percentageOfMentors)

console.log("percentage of students is: " + roughPercentageStudents + "%")

console.log("percentage of mentors is: " + roughPercentageMentors + "%")

11 changes: 10 additions & 1 deletion exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
function halve(number) {
// complete the function here
return number/2
}

var result = halve(12);

console.log(result);

var attemptOne = halve(20)

console.log(attemptOne)


var attemptTwo = halve(100)

console.log(attemptTwo)
11 changes: 10 additions & 1 deletion exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
function triple(number) {
// complete function here
return number*3
}

var result = triple(12);

console.log(result);


var result2 = triple(5)

console.log(result2)

var result3 = triple(10)

console.log(result3)
4 changes: 2 additions & 2 deletions exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Complete the function so that it takes input parameters
function multiply() {
// Calculate the result of the function and return it
function multiply(a, b) {
return a*b
}

// Assign the result of calling the function the variable `result`
Expand Down
7 changes: 6 additions & 1 deletion exercises/K-functions-parameters/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// Declare your function first

function divide(a,b) {
return a/b
}


var result = divide(3, 4);


console.log(result);
4 changes: 3 additions & 1 deletion exercises/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Write your function here
function createGreeting(a) {
return "Hello, my name is " + a
}

var greeting = createGreeting("Daniel");

Expand Down
6 changes: 6 additions & 0 deletions exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@

// Call the function and assign to a variable `sum`

function add(a,b) {
return a+b
}

let sum = add(13, 124)

console.log(sum);
6 changes: 6 additions & 0 deletions exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Declare your function here

function createLongGreeting(a, b) {
return `Hello, my name is ${a}, and I am ${b} years old`;
}



const greeting = createLongGreeting("Daniel", 30);

console.log(greeting);
11 changes: 11 additions & 0 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,14 @@ var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";



function mentorGreeting(a) {
var mentorCaps = a.toUpperCase()
return "HELLO " + mentorCaps + "!"
}

console.log(mentor1)

console.log(mentorGreeting(mentor1))
Empty file added extra/5
Empty file.
167 changes: 167 additions & 0 deletions extra/lesson2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
// //Create a function called isEven that should
// //take a number as an input
// // return a boolean indicating if the number is even or odd
// // Don’t use console.log inside the function itself
// // Example: isEven(100) should return true and isEven(53) should return false
// // Call your function with different arguments.
// // You don’t need to use an if statement for this exercise (we’ll get to if statements next…)

// function isEven (x) {
// return x % 2 === 0
// }

// console.log(isEven(5))
// console.log(isEven(8))

// // Create a function called moreThanSixGoals that should
// // take 2 numbers as input (the number of goals for each football team)
// // return a boolean value indicating if the total goals is more than 6
// // Don’t use console.log inside the function.
// // Example: moreThanSixGoals(2,3) should return false and moreThanSixGoals(5,2) should return true
// // Try calling your function with different arguments.
// // Ensure your function doesn't use an if statement for this exercise (we’ll get to if statements next…)

// function moreThanSixGoals(x, y) {
// return x+y > 6
// }

// console.log(moreThanSixGoals(0, 5))

// console.log(moreThanSixGoals(10, 1))

// console.log(moreThanSixGoals(6, 0))

// console.log(moreThanSixGoals(7, 2))
// -



// Create a function that gives you a message depending on your mood! It should:
// take one input
// return "Good job, you're doing great!" if you pass in "happy"
// return "Every cloud has a silver lining" if you pass in "sad"
// return "Beep beep boop" if you pass in a number
// return "I'm sorry, I'm still learning about feelings!" if you pass in anything else

// function mood(x) {
// if (x === "happy") {
// return "Good job, you're doing great!"
// }
// else if (x==="sad"){
// return "Every cloud has a silver lining"
// }
// else if (typeof x==="number"){
// return "Beep beep boop"
// }
// else {
// return "I'm sorry, I'm still learning about feelings!"
// }
// }

// console.log(mood("happy"))
// console.log(mood(5))


// If you type the following into Node Console (in order), what would you expect to see? Guess before trying it out.
// let num = 10
// num > 5 && num < 15 // true
// num < 10 || num === 10 // true
// false || true // t
// !true // false
// let greaterThan5 = num > 5 //
// !greaterThan5 // false
// !(num === 10) //false


// In pairs, write a function that checks a username is of an acceptable format for a user type.
// The function must:
// take two parameters: one for the username and one for the user type
// if the username starts with a capital letter and has length between 5 and 10 characters long,
// it must return "Username valid"; otherwise, it must return "Username invalid"
// if the user type is an admin or a manager, all usernames must return "Username valid"

// function (userName, userType) {
// if userName[0].toUppercase() ===
// }

// let a;
// console.log(a)

// const a;
// console.log(a);

// function sayHello() {
// console.log("Hello");
// //no return statement
// }

// let a = sayHello();


// console.log(a);

// Create the following array:
// const fruits = ['banana', 'apple', 'strawberry', 'kiwi', 'fig', 'orange'];
// Using the correct index, get the following values from the array:
// strawberry
// kiwi
// orange
// banana
// Be curious! What if you use an index that doesn’t have a value? What if
//you use a negative index? Or a string instead of a number index?

// let fuitArray = ["banana", "apple", "strawberry", "kiwi", "fig", "orange"];

// console.log(fuitArray[2]);
// console.log(fuitArray[3]);
// console.log(fuitArray[4]);
// console.log(fuitArray[5]);
// console.log(fuitArray[6]);
// console.log(fuitArray[-2]);


// We’re writing a ToDo List App. We need a function which:
// Takes an array of tasks (strings) as a parameter
// It should output the last task in the list in uppercase, after the words “Don’t forget to ”
// Hint: How do you make a string uppercase? MDN String
// Test your function:
// lastTask(['do the dishes', 'take out garbage', 'practice coding']);
// //should output: “Don't forget to PRACTICE CODING”

//

// function toDoListApp(myArray) {
// let lengthOf = myArray.length;
// return "Don't forget to " + myArray[lengthOf-1]
// }

// console.log(toDoListApp(lastTask))

// Now write a function called randomTask which
// Takes an array of tasks (strings) as a parameter
// Returns a random task from the list (don’t use console.log in the function)
// Hint: Look for help here - MDN Math
// Hint: Google how to generate a random number in JavaScript
// Test your function:
// console.log(randomTask['do the dishes', 'take out garbage', 'practice coding', 'clean house']);
// //should output different tasks each time

let lastTask = ["do the dishes", "take out garbage", "practice coding"];

function randomTask (arrayOfStrings) {
let randomElementNumber = Math.floor(Math.random()* arrayOfStrings.length)
return arrayOfStrings[randomElementNumber]

}
console.log(randomTask(lastTask))


// It's a simple one-liner:

// const randomElement = array[Math.floor(Math.random() * array.length)];
// For example:

// const months = ["January", "February", "March", "April", "May", "June", "July"];

// const random = Math.floor(Math.random() * months.length);
// console.log(random, months[random]);
Loading