Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
Closed
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: 4 additions & 0 deletions exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
console.log(`cd B-hello-world`)
console.log("Hello world");
console.log("I started to learn javascript!");
console.log("Good Afternoon");
console.log("I am thrilled!");
4 changes: 4 additions & 0 deletions exercises/C-variables/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Start by creating a variable `greeting`

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

console.log(message);
var message = "Hello everyone, welcome to the show!";
var typeOfMessage = typeof message;
console.log(message);
console.log(typeOfMessage);
5 changes: 4 additions & 1 deletion exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Start by creating a variable `message`

var greeting = "Good Morning ,";
var yourName = "my name is ";
var name = "Krrish"
var message = greeting + yourName;
console.log(message);
9 changes: 9 additions & 0 deletions exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
// Start by creating a variable `message`

console.log(message);
var message = "Hello my name is !!";
var myName = "Krishan Kumar";
console.log(message + myName.length);
//My name is Daniel and my name is 6 characters long

console.log(message);
console.log(
"My name is " + myName + " and it's " + myName.length + " character long"
);
5 changes: 5 additions & 0 deletions exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
const name = " Daniel ";
console.log(message);
const message =
"My name is " + name + " and my name is " + name.length + " characters long";
console.log(message.trim());


console.log(message);
4 changes: 4 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
var numberOfMentors = 15;
var numberOfStudents = 35;
var totalNumber = numberOfMentors + numberOfStudents;
console.log("Total number of students and mentors is : " + totalNumber);
7 changes: 7 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
var NumOfTotalPeople = 23;

var percentNum = numberOfStudents*100/NumOfTotalPeople;

console.log("Percentage of mentors " + Math.round(percentNum) + "%");
var percentNum = numberOfMentors*100/NumOfTotalPeople;
console.log("Percentage of students " + Math.round(percentNum) + "%");
6 changes: 6 additions & 0 deletions exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
function halve(number) {
// complete the function here
return number / 2;
}

var result = halve(12);
console.log(result);

var result = halve(5);
console.log(result);

var result = halve(19);
console.log(result);
2 changes: 1 addition & 1 deletion exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function triple(number) {
// complete function here
return number * 3;
}

var result = triple(12);

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

// Assign the result of calling the function the variable `result`
var result = multiply(3, 4);

console.log(result);
6 changes: 5 additions & 1 deletion exercises/K-functions-parameters/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Declare your function first

var result = divide(3, 4);
function divide(num1, num2) {
return num1 / num2;
}

var result = divide(3, 4);

console.log(result);
4 changes: 4 additions & 0 deletions exercises/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Write your function here

function createGreeting(name) {
return "Hello my name is " + name;
}

var greeting = createGreeting("Daniel");

console.log(greeting);
6 changes: 5 additions & 1 deletion exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Declare your function first
function bigSum(num1, num2) {
return num1 + num2;
}

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

var sum = bigSum(13, 124);
console.log(sum);
6 changes: 5 additions & 1 deletion exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Declare your function here

const greeting = createLongGreeting("Daniel", 30);
function createLongGreeting(name, num1) {
return "Hello, my name is " + name + " and I'm " + num1 + " years old";
}

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

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

//function to spelling name in uppercase

function greeting(message) {
return message.toUpperCase();
}
var greet_message = greeting("hello");

function getMentorName(name) {
return name.toUpperCase();
}

var mentor1 = getMentorName("Daniel");
console.log(greet_message + " " + mentor1);
var mentor2 = getMentorName("Irina");
console.log(greet_message + " " + mentor2);
var mentor3 = getMentorName("Mimi");
console.log(greet_message + " " + mentor3);
var mentor4 = getMentorName("Rob");
console.log(greet_message + " " + mentor4);
var mentor5 = getMentorName("Yohannes");
console.log(greet_message + " " + mentor5);
11 changes: 10 additions & 1 deletion extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
*/

function convertToUSD() {}
function convertToUSD(amount) {
let poundToDollar = 1.4 * amount;
return poundToDollar;
}

/*
CURRENCY CONVERSION
Expand All @@ -16,11 +20,16 @@ function convertToUSD() {}
*/

function convertToBRL() {}
function convertToBRL(amount) {
let transferFee = amount * 0.99;
let poundToReal = (transferFee * 5.7).toFixed(2);
return parseFloat(poundToReal);
}

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.

To run these tests type `npm run extraTo run the tests for just this one file, type `npm run extra-tests -- --testPathPattern 1-syntax-errors` into your terminal
To run these tests type `npm run extraTo run the tests for just this one file, type `npm run extra-tests -- --testPathPattern 1-currency-conversion` into your terminal
(Reminder: You must have run `npm install` one time before this will work!)
*/

Expand Down
24 changes: 15 additions & 9 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,33 @@
the final result to the variable goodCode
*/

function add() {

function add(num1, num2) {
let sumOfNum = num1 + num2;
return sumOfNum;
}

function multiply() {

function multiply(num1, num2) {
let multiplyNum = num1 * num2;
return multiplyNum;
}

function format() {

function format(num) {
let numToStr = "£" + num.toString();
return numToStr;
}

const startingValue = 2;

// Why can this code be seen as bad practice? Comment your answer.
let badCode =

/* BETTER PRACTICE */
let badCode = `${format(multiply(add(startingValue, 10), 2))}`;

let goodCode =
/* BETTER PRACTICE */

//let goodCode =
var addNum = add(startingValue, 10); //adding 10 to the starting value
let multiplyNum = multiply(addNum, 2); //multiplying the result of addNum by 2
let goodCode = format(multiplyNum); //formatting the multiplied num into a string
/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.

Expand Down
58 changes: 57 additions & 1 deletion extra/3-magic-8-ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,44 @@
Outlook not so good.
Very doubtful.
*/
const ansArray = [
//Very positive
"It is certain.",
"It is decidedly so.",
"Without a doubt.",
"Yes - definitely.",
"You may rely on it.",
//Positive
"As I see it, yes.",
"Most likely.",
"Outlook good.",
"Yes.",
"Signs point to yes.",
//Negative
"Reply hazy, try again.",
"Ask again later.",
"Better not tell you now.",
"Cannot predict now.",
"Concentrate and ask again.",
//Very negative
"Don't count on it.",
"My reply is no.",
"My sources say no.",
"Outlook not so good.",
"Very doubtful.",
];
function generateRandom() {
return Math.floor(Math.random() * ansArray.length);
}

// This should log "The ball has shaken!"
// and return the answer.
function shakeBall() {
const randomAnswer = ansArray[generateRandom()];

//Write your code in here
console.log("The ball has shaken!");
return randomAnswer;
}

/*
Expand All @@ -58,10 +91,30 @@ function shakeBall() {

This function should expect to be called with any value which was returned by the shakeBall function.
*/

function checkAnswer(answer) {
//Write your code in here
let answerTurns;
for (let i = 0; i < ansArray.length; i++) {
if (answer === ansArray[i]) {
answerTurns = i;
}
}
if (answerTurns < 5) {
return "very positive";
} else if (answerTurns >= 5 && answerTurns < 10) {
return "positive";
} else if (answerTurns >= 10 && answerTurns < 15) {
return "negative";
} else {
return "very negative";
}
}

let a = shakeBall();
console.log(checkAnswer(a));


/*
==================================
======= TESTS - DO NOT MODIFY =====
Expand Down Expand Up @@ -101,7 +154,10 @@ test("magic 8 ball returns different values each time", () => {
);
}

let seenPositivities = new Set(Array.from(seenAnswers.values()).map(checkAnswer));
let seenPositivities = new Set(
Array.from(seenAnswers.values()).map(checkAnswer)
);

if (seenPositivities.size < 2) {
throw Error(
"Expected to random answers with different positivities each time shakeBall was called, but always got the same one"
Expand Down
10 changes: 6 additions & 4 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// There are syntax errors in this code - can you fix it to pass the tests?

function addNumbers(a b c) {
function addNumbers(a, b, c) {
return a + b + c;
}

function introduceMe(name, age)
return "Hello, my name is " + name "and I am " age + "years old";
function introduceMe(name, age){
return "Hello, my name is " + name + " and I am " + age + " years old";
}


function getTotal(a, b) {
total = a ++ b;
return "The total is " + (a + b);

return "The total is total";
}
Expand Down
7 changes: 3 additions & 4 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// The syntax for this function is valid but it has an error, find it and fix it.

function trimWord(word) {
return wordtrim();
return word.trim();
}

function getStringLength(word) {
return "word".length();
return word.length;
}

function multiply(a, b, c) {
a * b * c;
return;
return a * b * c;
}

/*
Expand Down
Loading