-
-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NW6| FIDAA BASHIR | Module-JS1 | WEEK3 #190
base: main
Are you sure you want to change the base?
Changes from all commits
76f8ae3
29d74df
f92e05c
67e4d82
4d46444
f5c8974
d288602
3c74cfe
4790e5f
150892b
6376acf
41fe283
43c4493
54a46a7
a564df8
dd3bf6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
This is just an instruction for the first activity - but it is just for human consumption | ||
We don't want the computer to run these 2 lines - how can we solve this problem? | ||
/*This is just an instruction for the first activity - but it is just for human consumption | ||
We don't want the computer to run these 2 lines - how can we solve this problem?*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// trying to create an age variable and then reassign the value by 1 | ||
|
||
const age = 33; | ||
let age = 33; | ||
age = age + 1; | ||
console.log(age); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// Currently trying to print the string "I was born in Bolton" but it isn't working... | ||
// what's the error ? | ||
|
||
console.log(`I was born in ${cityOfBirth}`); | ||
const cityOfBirth = "Bolton"; | ||
console.log(`I was born in ${cityOfBirth}`); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
const 12HourClockTime = "20:53"; | ||
const 24hourClockTime = "08:53"; | ||
const twelveHourClockTime = "20:53"; | ||
const twentyFourHourClockTime = "08:53"; | ||
console.log(twelveHourClockTime); | ||
console.log(twentyFourHourClockTime); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
// Predict and explain first... | ||
|
||
function sum(a, b) { | ||
return; | ||
a + b; | ||
return a + b; | ||
} | ||
|
||
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
||
//the error here that we should place the a + b expression directly after the return keyword. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
// Predict and explain first... | ||
|
||
// Predict and explain first.. | ||
// This program should tell the user the last digit of each number. | ||
// Explain why getLastDigit is not working properly - correct the problem | ||
const num = 103; | ||
|
||
function getLastDigit() { | ||
return num.toString().slice(-1); | ||
function getLastDigit(num) { | ||
return num % 10; | ||
} | ||
|
||
console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
console.log(`The last digit of 806 is ${getLastDigit(806)}`); | ||
|
||
// This program should tell the user the last digit of each number. | ||
// Explain why getLastDigit is not working properly - correct the problem |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
|
||
// Predict and explain first... | ||
// this function should square any number but instead we're going to get an error | ||
// what is happening? How can we fix it? | ||
// the error here is the (num) variable is not defined within the square function. | ||
// to fix this error, we need to define the (num) variable within the square function, like this: | ||
|
||
function square(3) { | ||
return num * num; | ||
function square(num) { | ||
return num * num; | ||
} | ||
|
||
|
||
console.log(square(3)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,25 @@ | |
// Identify Reflex Angles: | ||
// When the angle is greater than 180 degrees and less than 360 degrees, | ||
// Then the function should return "Reflex angle" | ||
|
||
function getAngleType(angle) { | ||
if (angle < 90) { | ||
return "Acute angle"; | ||
} else if (angle == 90) { | ||
return "Right angle"; | ||
} else if (angle > 90 && angle < 180) { | ||
return "Obtuse angle"; | ||
} else if (angle == 180) { | ||
return "Straight angle"; | ||
} else if (angle > 180 && angle < 360) { | ||
return "Reflex angle"; | ||
} | ||
return "invalid angle"; | ||
} | ||
|
||
console.log(getAngleType(80)); | ||
console.log(getAngleType(90)); | ||
console.log(getAngleType(120)); | ||
console.log(getAngleType(180)); | ||
console.log(getAngleType(200)); | ||
console.log(getAngleType(540)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perfect! 👍 That's great you considered the invalid inputs as well, to return invalid angles! |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,28 @@ | |
// Given a card with an invalid rank (neither a number nor a recognized face card), | ||
// When the function is called with such a card, | ||
// Then it should throw an error indicating "Invalid card rank." | ||
|
||
function getCardValue(cardString) { | ||
const [rank, suit] = cardString.split("♠"); | ||
switch (rank) { | ||
case "2": | ||
case "3": | ||
case "4": | ||
case "5": | ||
case "6": | ||
case "7": | ||
case "8": | ||
case "9": | ||
case "10": | ||
return parseInt(rank); | ||
case "J": | ||
case "Q": | ||
case "K": | ||
return 10; | ||
case "A": | ||
return 11; | ||
default: | ||
throw new Error("Invalid card rank."); | ||
} | ||
} | ||
console.log(getCardValue(10)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great attempt to implement the function! Try to run your code again and find out how to fix the error if it gives you any error! We also need to write assertions using console.assert as the exercise asks us to do, in line 5! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done! We can also try different cases using console.log to make sure that the code works properly for any kind of input.