Total: 60 marks · Question 1–3 carry 10 marks each, Question 4–5 carry 15 marks each.
Write a function describeValue that takes any value and returns a string with two pieces of information joined by a space, a pipe, and another space:
<type of the value> | <truthy or falsy>
Examples:
| Call | Returns |
|---|---|
describeValue("hello") |
"string | truthy" |
describeValue("") |
"string | falsy" |
describeValue(25) |
"number | truthy" |
describeValue(0) |
"number | falsy" |
describeValue(true) |
"boolean | truthy" |
describeValue(null) |
"object | falsy" |
describeValue(undefined) |
"undefined | falsy" |
Watch out for these three. Think before you answer:
describeValue("0")— a string that looks like zerodescribeValue(NaN)— what doestypeof NaNgive?describeValue(null)— remember the strange thing we saw in class
Hint: you do not need a long
ifchain to find the type.typeofgives it to you. And a value can be put straight inside anifto test truthy or falsy.
Write a function getDayType that takes a day name and returns:
| Input day | Returns |
|---|---|
| Friday, Saturday | "Weekend" |
| Sunday, Monday, Tuesday, Wednesday, Thursday | "Working Day" |
| anything else | "Invalid Day" |
You must solve this with switch case, not with if / else.
It must also work when the student enters the day in any letter case:
| Call | Returns |
|---|---|
getDayType("Friday") |
"Weekend" |
getDayType("friday") |
"Weekend" |
getDayType("MONDAY") |
"Working Day" |
getDayType("Bandarban") |
"Invalid Day" |
Hint: two
caselines can share one result if you do not putbreakbetween them. And a string method can fix the letter case before theswitchstarts.
Write a function validateUsername that takes a username and checks it against these rules, in this order:
- Shorter than 4 characters → return
"Too Short" - Contains a space → return
"No Space Allowed" - Contains the word
adminanywhere, in any letter case → return"Reserved Word" - Otherwise → return
"Available"
The order matters. Look at the third example carefully.
| Call | Returns | Why |
|---|---|---|
validateUsername("rahim123") |
"Available" |
passes every rule |
validateUsername("ab") |
"Too Short" |
only 2 characters |
validateUsername("a b") |
"Too Short" |
it has a space, but the length rule is checked first |
validateUsername("abcd") |
"Available" |
exactly 4 is allowed |
validateUsername("rahim islam") |
"No Space Allowed" |
|
validateUsername("superadmin99") |
"Reserved Word" |
admin is in the middle |
validateUsername("Admin_Rahim") |
"Reserved Word" |
capital A must also be caught |
Hint:
.length,.includes(), and.toLowerCase().
Write a function getCngFare(distance, isNight, waitingMinutes) that returns the total fare in taka.
Fare rules:
- The minimum fare is 50 taka, and it covers the first 2 km.
- Every km after the first 2 km costs 15 taka.
- Waiting charge: 2 taka for every waiting minute.
- At night, the driver adds 20% on the whole fare — that means on the distance charge and the waiting charge together.
isNightshould default tofalseandwaitingMinutesshould default to0, sogetCngFare(5)must work on its own.
Return the number, do not round it and do not add the word "taka".
| Call | Returns | Working |
|---|---|---|
getCngFare(2) |
50 |
minimum fare |
getCngFare(1) |
50 |
still the minimum, never less |
getCngFare(5) |
95 |
50 + (3 × 15) |
getCngFare(10) |
170 |
50 + (8 × 15) |
getCngFare(5, false, 10) |
115 |
95 + (10 × 2) |
getCngFare(5, true) |
114 |
95 + 20% |
getCngFare(5, true, 10) |
138 |
115 + 20% |
Hint: build the fare step by step in a
letvariable, then apply the night charge at the very end.
Write an arrow function getChaseVerdict(target, scored, ballsLeft) for a cricket run chase.
Steps:
-
runsNeeded = target - scored -
If
runsNeededis 0 or less, the match is already won → return"Won" -
Otherwise, if
ballsLeftis 0 or less, there is no ball left to score → return"Lost" -
Otherwise, work out the required run rate:
requiredRate = (runsNeeded / ballsLeft) * 6 -
Pick the verdict from the rate:
Required rate Verdict 6 or less "Comfortable"more than 6, up to 12 "Tough"more than 12 "Almost Impossible" -
Return this exact sentence:
Need <runsNeeded> runs in <ballsLeft> balls | <verdict>Always write
runsandballs, even when the number is 1.
| Call | Returns |
|---|---|
getChaseVerdict(200, 200, 12) |
"Won" |
getChaseVerdict(200, 190, 0) |
"Lost" |
getChaseVerdict(100, 90, 12) |
"Need 10 runs in 12 balls | Comfortable" |
getChaseVerdict(100, 80, 12) |
"Need 20 runs in 12 balls | Tough" |
getChaseVerdict(100, 70, 12) |
"Need 30 runs in 12 balls | Almost Impossible" |
getChaseVerdict(150, 149, 1) |
"Need 1 runs in 1 balls | Comfortable" |
Hint: use a template string for the sentence. Write it as
const getChaseVerdict = (target, scored, ballsLeft) => { ... };
-
Use the exact function names given. Spelling and capital/small letters must match.
-
Every function must
returnits answer. Do not useconsole.logfor the answer.// ❌ this gives 0 function add(a, b) { console.log(a + b); } // ✅ this is correct function add(a, b) { return a + b; }
-
Return the text exactly as shown, including spaces and capital letters.
"Weekend"is correct,"weekend"is not. -
You may only use what we covered in class: variables, operators, strings, template strings,
if / else,switch, ternary, and functions. No arrays, no loops, no objects. -
Part marks are given. If your function works for some cases but not all, you still get marks for the cases that work. So attempt every question, even if you cannot make it perfect.
- Write all five answers in one file and name it
answer.js - You may use comments to specify the question number (example: //Question No. 1)
- Repository Setup: Create a personal GitHub repository and push your completed files.
- Visibility: Set the repository to Public.
- Submission: Paste the direct repository URL into the assignment submission box. Do not submit individual files or archives.
- 60 Marks: September 2, 2026, 11:59 PM
- 50 Marks: September 3, 2026, 11:59 PM
- Zero Tolerance: Plagiarism will result in 0 marks.
- No Copying: Do not copy code from peers or online sources.
- No AI Code: Do not use AI generators. We actively run AI code detection tools.
- Original Work: All code must be 100% your own.