29/12/2025, 23:23 JavaScript Assignment - 25 Questions
JavaScript Coding Assignment
Trainer - S MUZAMMIL JAVED
Total Marks: 100 | Due Date: 30 December 2025
⚠️ IMPORTANT SUBMISSION RULES
1. Submit your GitHub repository link only
2. Create 2 files: [Link] and [Link]
3. Follow the pattern: // Question 1: ... then your code
4. NO COPYING ALLOWED - Each student must write original code
5. Repository must be PUBLIC on GitHub
[Link] 1/9
29/12/2025, 23:23 JavaScript Assignment - 25 Questions
📝 Assignment Questions (25 Total)
Question 1: Variable Declarations and Initialization
Create three variables: productName (string with value "Laptop"), price (number with
value 999.99), and inStock (boolean with value true). [Link] all three variables in a
single statement.
Question 2: Mathematical Operations
Calculate and display:
The remainder when 27 is divided by 4
The square of 12 (using exponentiation operator ** )
The result of incrementing 8 by 1 using the ++ operator
The result of decrementing 15 by 2 using the -= operator
Question 3: String Concatenation and Case Conversion
Create two string variables: firstName = "alex" and lastName = "SMITH" .
Concatenate them with a space, then convert the result to proper case (first letter
uppercase, rest lowercase). Also find the total length of the full name.
Question 4: if-else Conditional Logic
Write an if-else statement that checks a temperature variable. If temperature is
above 30, [Link] "Hot day". If between 20 and 30 (inclusive), [Link] "Pleasant
day". Otherwise, [Link] "Cold day". Test with temperature = 25.
[Link] 2/9
29/12/2025, 23:23 JavaScript Assignment - 25 Questions
Question 5: Comparison Operators
Create three comparison operations:
Check if 15 is strictly equal to "15"
Check if 20 is greater than 15 AND less than 25
Check if 10 is not equal to 10 OR 5 is greater than 3
Question 6: Array Manipulation - Basics
Create an array colors with values ["red", "green", "blue"]. Then:
Add "yellow" to the end
Remove the first element
Insert "purple" at index 1
[Link] the final array and its length
Question 7: Array Manipulation - splice()
Start with array fruits = ["apple", "banana", "cherry", "date",
"elderberry"] . Use splice() to:
Remove "cherry"
Replace "date" with "dragonfruit"
Extract the middle 3 elements into a new array
Question 8: for Loop - Number Sequence
Write a for loop that prints numbers from 1 to 10, but skips number 5 using
continue , and stops at 8 using break . Also calculate the sum of all printed numbers.
[Link] 3/9
29/12/2025, 23:23 JavaScript Assignment - 25 Questions
Question 9: Nested for Loop - Pattern
Write nested for loops to create this pattern:
*
**
***
****
*****
Question 10: String Methods - Search and Extract
Given text = "The quick brown fox jumps over the lazy dog" :
Find the position of "fox"
Extract "brown fox" using substring/slice
Check if the text contains "dog"
Get the character at position 10
Question 11: String Replacement
Given sentence = "I love JavaScript and JavaScript is awesome" :
Replace the first "JavaScript" with "coding"
Replace ALL "JavaScript" with "JS"
Replace "awesome" with uppercase "AWESOME"
[Link] 4/9
29/12/2025, 23:23 JavaScript Assignment - 25 Questions
Question 12: Number Rounding and Formatting
Given num = 123.456789 :
Round to 2 decimal places
Round to nearest integer
Get the floor value
Get the ceiling value
Format to show exactly 4 decimal places
Question 13: Random Number Generation
Generate:
A random integer between 1 and 100 (inclusive)
A random decimal between 0 and 1 with 3 decimal places
A random number between 50 and 75 (inclusive)
Question 14: Type Conversion
Perform these conversions:
Convert string "123" to number
Convert string "45.67" to decimal (float)
Convert number 789 to string
Check the type of "true" after converting to boolean
[Link] 5/9
29/12/2025, 23:23 JavaScript Assignment - 25 Questions
Question 15: Date and Time Operations
Create a Date object for the current time and:
Extract the year, month (0-11), and day
Get the hours in 24-hour format
Format it as "YYYY-MM-DD"
Create a specific date for December 25, 2024
Question 16: Function - Basic Calculator
Write a function calculate that takes two numbers and an operator (+, -, *, /) as
parameters and returns the result. Handle division by zero by returning "Error: Division by
zero".
Question 17: Function - Local vs Global Variables
Create a global variable globalCounter = 0 . Write a function incrementCounter
that declares a local variable with the same name and increments it, while also
incrementing the global variable. Show the difference after calling the function twice.
Question 18: switch Statement - Day of Week
Write a switch statement that takes a number (0-6) and returns the corresponding day
name (0=Sunday, 1=Monday, etc.). Include a default case for invalid numbers.
Question 19: while Loop - Countdown
Write a while loop that starts at 10 and counts down to 1, printing each number. Then
print "Blast off!". Also calculate the factorial of 5 using a while loop.
[Link] 6/9
29/12/2025, 23:23 JavaScript Assignment - 25 Questions
Question 20: do...while Loop - User Input Simulation
Create a do...while loop that simulates asking for a password. Start with
enteredPassword = "" and keep "asking" (incrementing a counter) until
enteredPassword === "secret123" or 5 attempts are made.
Question 21: Array Methods with for Loop
Given numbers = [12, 45, 78, 23, 56, 89, 34] :
Use a for loop to find the maximum value
Use a for loop to calculate the average
Create a new array with only numbers greater than 50
Reverse the array without using reverse() method
Question 22: Event Handling Simulation
Create a function handleClick that:
Gets a value from an input field with id "username"
Checks if it's empty and shows an alert if so
Otherwise, displays "Welcome, [username]!" in a paragraph with id "greeting"
Resets the input field after greeting
[Link] 7/9
29/12/2025, 23:23 JavaScript Assignment - 25 Questions
Question 23: Form Validation Function
Write a function validateForm that:
Takes email and password as parameters
Returns true if email contains "@" and password length ≥ 8
Otherwise returns false with specific error messages
Test with multiple test cases
Question 24: Temperature Converter
Create a function convertTemperature that:
Takes a temperature and a unit ("C" or "F") as parameters
Converts Celsius to Fahrenheit: (C × 9/5) + 32
Converts Fahrenheit to Celsius: (F - 32) × 5/9
Returns the converted value with 1 decimal place
Question 25: Shopping Cart Array Operations
Create an array cart = [] and write these functions:
addItem(name, price) : Adds item object to cart
removeItem(name) : Removes item by name
calculateTotal() : Returns sum of all item prices
applyDiscount(percent) : Applies discount to total
listItems() : Returns array of just item names
[Link] 8/9
29/12/2025, 23:23 JavaScript Assignment - 25 Questions
🚨 PLAGIARISM WARNING
- Copying from other students will result in ZERO marks
- Similar code will be detected automatically
- Both copier and provider will receive zero
- Write your own code - learn by doing!
[Link] 9/9