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
2 changes: 1 addition & 1 deletion exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log("Hello world");
console.log( 1 ,"Hello azadeh", 12.4, 'bye');
5 changes: 5 additions & 0 deletions exercises/C-variables/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Start by creating a variable `greeting`
let greeting = "Hello Azadeh"



console.log(greeting);
console.log(greeting);
console.log(greeting);
2 changes: 2 additions & 0 deletions exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Start by creating a variable `message`
const message = "this is a string";

console.log(message);
console.log(typeof message);
4 changes: 3 additions & 1 deletion exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Start by creating a variable `message`

const greetingStart = 'hello , I am ';
const myName = 'Azadeh'
const message= greetingStart + myName;
console.log(message);
6 changes: 5 additions & 1 deletion exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Start by creating a variable `message`

const myName="Azadeh";
const intro = "My name is";
const message = intro + " " + myName + " "+ "and my name is "+ myName.length + " characters long ";
console.log(message);


7 changes: 5 additions & 2 deletions exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const name = " Daniel ";

const name = " Daniel ".trim();
const intro = "My name is";
const message = intro + " " + name + " "+ "and my name is "+ name.length + " characters long ";
console.log(message);


10 changes: 10 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
const numberOfMentors = 5;
const numberOfStudents = 30;
const mentorsNum = "Number of mentors: "+ numberOfMentors;
const studentNum = "Number of students: " + numberOfStudents;
const totalNum = "Total number of students and mentors:" + (numberOfMentors + numberOfStudents);


console.log(mentorsNum);
console.log(studentNum);
console.log (totalNum);
16 changes: 14 additions & 2 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
const numberOfStudents = 15;
const numberOfMentors = 8;
const totalNumber = numberOfMentors+numberOfStudents;


const percentageOfMentors = (numberOfMentors/totalNumber)*100 ;
const percentageOfStudents = (numberOfStudents/totalNumber)*100 ;
const roundPercentageOfMentors = "Percentage Mentors:" + Math.round( percentageOfMentors) +"%";
const roundPercentageOfStudents = "Percentage students:" + Math.round( percentageOfStudents)+"%";

console.log( roundPercentageOfMentors);
console.log(roundPercentageOfStudents);


2 changes: 1 addition & 1 deletion exercises/J-functions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ a) _call_ it with an input and
b) assign the returned value to a variable

```js
var result = double(2);
var result = double();

console.log(result); // 4
```
Expand Down
2 changes: 1 addition & 1 deletion exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function halve(number) {
// complete the function here
return number / 2;
}

var result = halve(12);
Expand Down
1 change: 1 addition & 0 deletions exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function triple(number) {
// complete function here
return number * 3;
}

var result = triple(12);
Expand Down
3 changes: 2 additions & 1 deletion exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Complete the function so that it takes input parameters
function multiply() {
function multiply( a , b ) {
return a * b;
// Calculate the result of the function and return it
}

Expand Down
4 changes: 3 additions & 1 deletion exercises/K-functions-parameters/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Declare your function first

function divide(a,b){
return a/b;
}
var result = divide(3, 4);

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

var greeting = createGreeting("Daniel");

Expand Down
5 changes: 4 additions & 1 deletion exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Declare your function first

function adds(a , b){
return a + b;
}
var sum = adds(13 , 124);
// Call the function and assign to a variable `sum`

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

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

console.log(greeting);

20 changes: 20 additions & 0 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,23 @@ var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";
function upperCaseName ( mentor ){
return mentor.toUpperCase( )
}
function greeting( hi,name){
const mentor = upperCaseName(name)
return hi.concat( mentor)
}
const printName1= greeting("Hello ",mentor1);
const printName2= greeting("Hello " ,mentor2);
const printName3= greeting("Hello " ,mentor3);
const printName4= greeting("Hello " ,mentor4);
const printName5= greeting("Hello " ,mentor5);
console.log (printName1);
console.log (printName2);
console.log (printName3);
console.log (printName4);
console.log (printName5);



9 changes: 7 additions & 2 deletions extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

function convertToUSD() {}
function convertToUSD( pound ) {
return pound * 1.4;
}

/*
CURRENCY CONVERSION
Expand All @@ -15,7 +17,10 @@ function convertToUSD() {}
They have also decided that they should add a 1% fee to all foreign transactions, which means you only convert 99% of the £ to BRL.
*/

function convertToBRL() {}
function convertToBRL(pound) {
let brl = pound * 5.7 ;
return Number( ( brl - (brl * (1 / 100)) ).toFixed(2) );
}

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
20 changes: 11 additions & 9 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,28 @@
the final result to the variable goodCode
*/

function add() {

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

function multiply() {

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

function format() {

}
function format( number) {
return `£${number}`;
//"# "+number;
}

const startingValue = 2;

// Why can this code be seen as bad practice? Comment your answer.
let badCode =
let badCode = "£"+((startingValue+10 )*2);

/* BETTER PRACTICE */

let goodCode =
let goodCode = format( multiply( add( startingValue ,10 ) ,2 ) )


/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
51 changes: 47 additions & 4 deletions extra/3-magic-8-ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,50 @@
Very doubtful.
*/

// This should log "The ball has shaken!"
// and return the answer.

const veryNegativeAnswers = [
"Don't count on it.",
'My reply is no.',
'My sources say no.',
'Outlook not so good.',
'Very doubtful.',
];
const negativeAnswers = [
'Reply hazy, try again.',
'Ask again later.',
'Better not tell you now.',
'Cannot predict now.',
'Concentrate and ask again.',
];
const positiveAnswers = [
'As I see it, yes.',
'Most likely.',
'Outlook good.',
'Yes.',
'Signs point to yes.',
];
const veryPositiveAnswers = [
'You may rely on it',
'You may rely on it',
'It is decidedly so.',
'It is certain.',
];
const possibleAnswers = veryNegativeAnswers.concat(
negativeAnswers,
positiveAnswers,
veryPositiveAnswers
);
// This should log "The ball has shaken!"
// and return the answer.
function shakeBall() {
//Write your code in here
const randomIndex = Math.floor(Math.random() * possibleAnswers.length);
const randomAnswer = possibleAnswers[randomIndex];
const message = 'The ball has shaken!';
console.log(message);
return randomAnswer;
}

/*
Expand All @@ -55,11 +95,14 @@ function shakeBall() {
- positive
- negative
- very negative

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
const answerIndex = possibleAnswers.indexOf(answer);
if (answerIndex >= 15) return 'very positive';
if (answerIndex >= 10) return 'positive';
if (answerIndex >= 5) return 'negative';
return 'very negative';
}

/*
Expand All @@ -76,12 +119,12 @@ To run the tests for just this one file, type `npm test -- --testPathPattern 3-m
test("whole magic 8 ball sequence", () => {
const consoleLogSpy = jest.spyOn(global.console, "log");
const answer = shakeBall();

expect(typeof answer).toEqual("string");

expect(consoleLogSpy).toHaveBeenCalledTimes(1);
expect(consoleLogSpy).toHaveBeenLastCalledWith("The ball has shaken!");

expect(checkAnswer(answer)).toBeOneOf([
"very positive",
"positive",
Expand Down
12 changes: 6 additions & 6 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,16 +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;
const total = a + b;

return "The total is total";
return "The total is " + total;
}

/*
Expand Down
11 changes: 6 additions & 5 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// The syntax for this function is valid but it has an error, find it and fix it.

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

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

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

/*
Expand Down
4 changes: 4 additions & 0 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
// Add comments to explain what this function does. You're meant to use Google!
// The Math.random() function returns a floating-point, pseudo-random number in the range 0 to less than 1 (inclusive of 0, but not 1) with approximately uniform distribution over that range — which you can then scale to your desired range. The implementation selects the initial seed to the random number generation algorithm; it cannot be chosen or reset by the user.
function getRandomNumber() {
return Math.random() * 10;
}

// Add comments to explain what this function does. You're meant to use Google!
// concatanetion two words to each other
function combine2Words(word1, word2) {
return word1.concat(word2);
}

function concatenate(firstWord, secondWord, thirdWord) {
// Write the body of this function to concatenate three words together.
// Look at the test case below to understand what this function is expected to return.
// return firstWord +" " + secondWord + " "+thirdWord
return `${firstWord} ${secondWord} ${thirdWord}`
}

/*
Expand Down
Loading