Skip to content
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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.formatOnSave": true
"editor.formatOnSave": true,
"terminal.integrated.sendKeybindingsToShell": true
}
4 changes: 2 additions & 2 deletions src/00-hello-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export {};
*/

const helloWorld = function() {
return "";
return "Hello World";
};

console.log(); // Expected output: "Hello World"
console.log(helloWorld()); // Expected output: "Hello World"
7 changes: 6 additions & 1 deletion src/01-syntax-error.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
export {};

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

const result = addNumbers(1, 3, 4);
const result1 = addNumbers(2, 3, 5);
const result2 = addNumbers(1, 3, 888);

console.log(result); // Expected output: 8
console.log(result1);
console.log(result2);
6 changes: 3 additions & 3 deletions src/02-syntax-error.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export {};

function addNumbers(a, b, c)
a + b + c;

function addNumbers(a:number, b: number, c: number){
return a + b + c;
}
const result = addNumbers(1, 3, 4);
console.log(result); // Expected output: 8
2 changes: 1 addition & 1 deletion src/03-syntax-error.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export {};

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

Expand Down
4 changes: 2 additions & 2 deletions src/04-logic-error.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export {};

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

const result = trimWord(" CODELEX ");
Expand Down
10 changes: 7 additions & 3 deletions src/05-boolean.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
export {};

const isHappy = "true";
const isHappy = true;

if (isHappy == false) {
if (isHappy) {
console.log("I am happy");
} else {
console.log("I am not happy");
}

// Expected output: "I am happy"
// Expected output: "I am happy

//2. isHappy ? console.log("I am happy") : console.log("I am not happy");

//3. console.log(`I am ${isHappy ? '' : 'not' }happy`)
4 changes: 2 additions & 2 deletions src/06-logic-error.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export {};

function trimWord(word) {
return word.trim;
function trimWord(word: string): string{
return word.trim();
}

const result = trimWord(" CODELEX ");
Expand Down
4 changes: 2 additions & 2 deletions src/07-logic-error.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export {};

function trim(word) {
return "word".trim();
function trim(word: string): string {
return word.trim();
}

const result = trim("CODELEX ");
Expand Down
6 changes: 3 additions & 3 deletions src/08-function-output.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export {};

function getNumber() {
return Math.random() * 10;
function getRandomNumber() {
return Math.round(Math.random() * 10);
}

const result = null; // call the function created above and put the result inside the variable
const result = getRandomNumber(); // call the function created above and put the result inside the variable
console.log(result); // Expected output: {random number}
6 changes: 3 additions & 3 deletions src/09-logic-error.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export {};

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

}

const result = multiply(1, 3, 4);
Expand Down
7 changes: 4 additions & 3 deletions src/10-function-output.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export {};

function s(w1, w2) {
return w1.concat(' ').concat(w2);
function joinString(w1: string, w2: string): string {
//return w1.concat(' '). concat(w2);
return w1.concat(" ", w2);
}

const result = undefined; // concatenate two strings - 'hello', 'world', using the function above
const result = joinString ('hello','world'); // concatenate two strings - 'hello', 'world', using the function above
console.log(result); // Expected output: "hello world"
8 changes: 7 additions & 1 deletion src/11-function-output.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
export {};

function concatenate(firstWord, secondWord, thirdWord) {
function concatenate(
firstWord: string,
secondWord: string,
thirdWord: string):
string {

return `${firstWord} ${secondWord} ${thirdWord}`;
// Write the body of this function to concatenate three words together with space between them
}

Expand Down
30 changes: 29 additions & 1 deletion src/12-truncate-string.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
export {};

console.log(truncateString("CODELEX", 4)); // Expected output: CODE
function truncateString(str: string, length: number):string{
//return str.substring(0,length)


// Expected output: CODE


let result = "";

for(let i = 0; i < length; i++){
console.log('i, str[i]:', i, str[i]);

result = result + str[i];
console.log('result: ', result);
console.log('=======================');
}
return result;

}
console.log (truncateString ("CODELEX", 4));









16 changes: 13 additions & 3 deletions src/13-is-blank.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
export {};

/**
* Create a function called isBlank, which checks if passed string is blank or not
*/

// Create a function called isBlank, which checks if passed string is blank or not


function isBlank(value: string | null): boolean {
if(value === null) {
return true;
}
if (value.trim() === ""){
return true;
}
return false;
}

console.log(isBlank(null)); // Expected output: true
console.log(isBlank("")); // Expected output: true
Expand Down
11 changes: 9 additions & 2 deletions src/14-repeat-string.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
export {};

const repeatString = () => {};
const repeatString = (str: string, timesToRepeat: number): string => {
// return str.repeat(timesToRepeat);
let result = str;
for(let i = 1; i < timesToRepeat; i++){
result += str; //result = result + str;
}
return result;
};

console.log(repeatString("a", 4)); // Expected output: 'aaaa'
console.log(repeatString("b", 5)); // Expected output: 'bbbbb'
console.log(repeatString("bob", 5)); // Expected output: 'bbbbb'
4 changes: 3 additions & 1 deletion src/15-greatest-number.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export {};

function greatest(x, y) {}
function greatest(x: number, y: number) {

}

console.log(greatest(1, 2)); // Expected output: 2
console.log(greatest(5, 2)); // Expected output: 5
4 changes: 3 additions & 1 deletion src/16-tax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export {};
*/

// You are allowed to change only this function
function calculateSalesTax() {}
function calculateSalesTax(price: number): string {
return (price * 0.21).toFixed(2);
}

const product = "You don't know JS";
const price = 19.99;
Expand Down
5 changes: 4 additions & 1 deletion src/17-format-currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ export {};
*/

// You are allowed to change only this function
function formatCurrency() {}

function formatCurrency(num: number): string{
return num.toFixed(2)
}

function calculateSalesTax(price: number) {
return price * 0.21;
}
Expand Down
13 changes: 11 additions & 2 deletions src/18-currency-conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ export {};
*/

// You are allowed to change only this function
function convertToUSD() {}
/*
const CONVERSION_RATE_EUR_USD = 1.09;

function convertToUSD() {

}
function addFee(price: number): number{
return price + price * CONVERSION_FEE;
}


const product = "You don't know JS";
const price = 19.99;
const priceInUSD = convertToUSD(price);
const priceInUSD = convertToUSD(price );

console.log("Product: " + product);
console.log("Price: $" + priceInUSD);
Expand Down
23 changes: 19 additions & 4 deletions src/19-currency-conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,29 @@ export {};
*/

// You are allowed to change this function
function convertToUSD(price) {}

const CONVERSION_FEE = 0.02;
const CONVERSION_RATE_EUR_USD = 1.09;
const CONVERSION_RATE_EUR_BRL = 5.6;
const CONVERSION_RATE_EUR_YEN = 155.6;

function formatCurrency(num: number): string{
return num.toFixed(2);
}
function addFee(price: number): number{
return price + price * CONVERSION_FEE;
}
function convertCurrency(price: number,rate: number): number {
return price * rate;
}
// You are allowed to change this function
function convertToBRL(price) {}


const product = "You don't know JS";
const price = 12.5;
const priceInUSD = convertToUSD(price);
const priceInBRL = convertToBRL(price);
const convertedToUSD = convertCurrency(price, CONVERSION_RATE_EUR_USD);
const priceInUSD = formatCurrency(addFee(convertedToUSD));
const priceInBRL = formatCurrency(addFee(convertCurrency(price, CONVERSION_RATE_EUR_BRL)));

console.log("Product: " + product);
console.log("Price: $" + priceInUSD);
Expand Down
7 changes: 6 additions & 1 deletion src/20-arrays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ export {};
* - https://javascript.info/array
*/

console.log(stringToArray(["John Doe"])); // Expected output: ['John', 'Doe']
function stringToArray(fullName: string): string[] {
return fullName.split(" ");
}

const nameArray = stringToArray("John Doe");
console.log(nameArray); // Expected output: ['John', 'Doe']
13 changes: 6 additions & 7 deletions src/21-map.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
export {};

function tidyUpString(str) {
return str
.trim()
.toLowerCase()
.replace("/", "");
function tidyUpString(str: string): string {
return str.trim().toLowerCase().replace("/", "");
}

// You are allowed to edit this function
function capitalise(str) {}
function capitalise(str: string): string {
return str.charAt(0).toUpperCase() + str.slice(1);
}

const mentors = ["/Daniel ", "irina ", " Gordon", "ashleigh "];
let mentorsTidy; // You are allowed to edit this line
let mentorsTidy = mentors.map((mentor) => capitalise(tidyUpString(mentor))); // You are allowed to edit this line

console.log(mentorsTidy); // Expected output: ["Daniel", "Irina", "Gordon", "Ashleigh"]
3 changes: 2 additions & 1 deletion src/22-sort.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export {};

const letters = ["a", "n", "c", "e", "z", "f"];
let sortedLetters; // You are allowed to change only this line
let sortedLetters = [...letters].sort(); // You are allowed to change only this line

console.log(sortedLetters); // Expected output: [ 'a', 'c', 'e', 'f', 'n', 'z' ]

24 changes: 22 additions & 2 deletions src/23-min-max.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,29 @@ export {};
* one of which does not use built-in Math methods.
*/

const min = array => {};
const min = (array: any) => {
let min = array[0];
for (let i = 1; i < array.length; i++) {
if (array[i] < min) {
min = array[i];
}
}
return min;
};

const max = array => {};
const max = (array: any) => {
let max = array[0];
for (let i = 1; i > max; i++) {
if (array[i] > max) {
max = array[i];
}
}
return max;
};
{
const min = (array: any) => Math.min(...array);
const max = (array: any) => Math.max(...array);
}

console.log(min([1, 2, 3, 4, 5])); // Expected output: 1
console.log(min([9, -3, 6])); // Expected output: -3
Expand Down
4 changes: 3 additions & 1 deletion src/24-looping-with-conditions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export {};

function onlyTheAces(arr) {}
function onlyTheAces(arr: string[]): string[] {
return arr.filter(element => element === "Ace");
}

console.log(onlyTheAces(["Ace", "King", "Queen", "Jack", "Ace"])); // Expected result: ['Ace', 'Ace']
Loading