Skip to content
Open
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
20 changes: 10 additions & 10 deletions src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* greet("Hamza") logs "Hello Hamza"
*/
function greet(name: string): void {
// Your code here
console.log(`Hello ${name}`);
}

/**
Expand All @@ -20,9 +20,7 @@ function greet(name: string): void {
* isOdd(10) -> false
*/
function isOdd(n: number): boolean {
// Your code here

return false; // replace false with what you see is fit
return n % 2 !== 0; // replace false with what you see is fit
}

/**
Expand All @@ -35,9 +33,8 @@ function isOdd(n: number): boolean {
* oddsSmallerThan(15) -> 7; // the odd numbers being 1, 3, 5, 7, 9, 11, 13
*/
function oddsSmallerThan(n: number): number {
// Your code here

return -1; // replace -1 with what you see is fit
return Math.floor(n / 2);
// replace -1 with what you see is fit
}

/**
Expand All @@ -51,9 +48,12 @@ function oddsSmallerThan(n: number): number {
* squareOrDouble(9) -> 81; // (9 ^ 2)
*/
function squareOrDouble(n: number): number {
// Your code here

return -1; // replace -1 with what you see is fit
if (n % 2 === 0) {
return n * 2;
} else {
return n * n;
}
// replace -1 with what you see is fit
}

export { greet, isOdd, oddsSmallerThan, squareOrDouble };