Skip to content
This repository was archived by the owner on Oct 26, 2020. It is now read-only.

Javascript/Nosayba #89

Open
wants to merge 11 commits into
base: master
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
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/week-1/2-mandatory/1-syntax-errors.js"
}
]
}
22 changes: 16 additions & 6 deletions week-1/2-mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
// 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;


function getTotal(a, b) {
total = a + b;
// Use string interpolation here
return "The total is %{total}"
return `The total is ${total}`
}


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

Expand All @@ -22,6 +27,11 @@ To run these tests type `node 1-syntax-errors.js` into your terminal

const util = require('util');


/* ======= TESTS - DO NOT MODIFY ===== */

// To run these tests type `node 1-syntax-errors.js` into your terminal

function test(test_name, actual, expected) {
let status;
if (actual === expected) {
Expand Down
28 changes: 20 additions & 8 deletions week-1/2-mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
// The syntax for this function is valid but it has an error, find it and fix it.

function trimWord(word) {
return wordtrim();
function trimWord(Word) {

return Word.trim();
}

console.log(trimWord(" CodeYourFuture "));


function getWordLength(word) {
return "word".length()

let wordLength = "A wild sentence appeared!";
return wordLength.length;
}


console.log(getWordLength());


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

return a * b * c;

}
console.log(multiply(2,3,6));


/* ======= TESTS - DO NOT MODIFY =====
/* ======= 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 `node 2-logic-error` into your terminal
*/
To run these tests type `node 2-logic-error` into your terminal*/

const util = require('util');

Expand Down
24 changes: 17 additions & 7 deletions week-1/2-mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
// Add comments to explain what this function does. You're meant to use Google!
// This function round the decimal number to the nearset whole number
function getNumber() {
return Math.random() * 10;
}

// Add comments to explain what this function does. You're meant to use Google!
// The concat() method is used to join two or more strings.
function s(w1, w2) {
return w1.concat(w2);
}

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.
function concatenate(firstword, secondWord, thirdWord) {

const join = firstword.concat(" "+secondWord +" " + thirdWord);


return join;
}

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
console.log(concatenate("code", "your", "future"));





/* ======= 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 `node 3-function-output` into your terminal
*/

Expand Down
30 changes: 26 additions & 4 deletions week-1/2-mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
Sales tax is 20% of the price of the product
*/

function calculateSalesTax() {}
function calculateSalesTax(productPrice) {
saleTax= 20/100;
return productPrice*saleTax+productPrice ;

}


console.log(calculateSalesTax(15));

/*
CURRENCY FORMATTING
Expand All @@ -14,12 +21,27 @@ function calculateSalesTax() {}
They must also start with the currency symbol
Write a function that adds tax to a number, and then transforms the total into the format £0.00

Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
Remember that the prices must include the sales tax (hint: you already
wrote a function for this!)
*/

function addTaxAndFormatCurrency() {}

/* ======= TESTS - DO NOT MODIFY =====
function addTaxAndFormatCurrency(productPrice) {

saleTax= 20/100;
currency= "£" ;


salePrice= productPrice* saleTax+ productPrice;
return currency + salePrice.toFixed(2) ;

}





/* ======= 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 `node 4-tax.js` into your terminal
*/
Expand Down
15 changes: 13 additions & 2 deletions week-1/3-extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

function convertToUSD() {}
function convertToUSD(pounds) {

let exchange = pounds * 1.4 ;
return exchange;

}

/*
CURRENCY FORMATTING
Expand All @@ -15,7 +20,13 @@ 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 currency = (pound* 5.7) * 1.01;

return currency ;

}

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
18 changes: 13 additions & 5 deletions week-1/3-extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,34 @@
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(a) {

return `£${a}`

}

const startingValue = 2

// Why can this code be seen as bad practice? Comment your answer.
let badCode =
let badCode = format(multiply(add(startingValue, 10 ), 2));

/* BETTER PRACTICE */
let adds= add(startingValue,10);
let multiplies = multiply(adds , 2);


let goodCode =
let goodCode = format(multiplies);

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
38 changes: 32 additions & 6 deletions week-2/2-mandatory/1-fix-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Look at the tests and see how you can fix them.

function mood() {
let isHappy = true;
let isHappy = false;

if (isHappy) {
return "I am happy";
Expand All @@ -11,8 +11,15 @@ function mood() {
}
}


function greaterThan10(num) {
let isBigEnough;
}
console.log(mood());

function greaterThan10() {
let num = 10;
let isBigEnough= num;

if (isBigEnough) {
return "num is greater than 10";
Expand All @@ -21,24 +28,43 @@ function greaterThan10(num) {
}
}


function sortArray(letters) {
let sortedLetters = letters;
let sortedLetters = letters;}

console.log(greaterThan10());


function sortArray() {
let letters = ["a", "n", "c", "e", "z", "f"];
let sortedLetters= ["a", "c", "e", "f", "n", "z"];

return sortedLetters;
}


function first5(numbers) {
let sliced;
}

console.log(sortArray());


function first5() {
let numbers = [1, 2, 3, 4, 5, 6, 7, 8];
let sliced= [1, 2, 3, 4, 5];

return sliced;
}
console.log(first5());

function get3rdIndex(arr) {
let index = 3;
let element;

return element;
function get3rdIndex(array) {

return array[3];
}
console.log(get3rdIndex(["fruit", "banana", "apple", "strawberry", "raspberry"]));
console.log(get3rdIndex([11, 37, 62, 18, 19, 3, 30]));

/* ======= TESTS - DO NOT MODIFY ===== */

Expand Down
Loading