JavaScript Assignment Solutions
1. Function to check if number is even or not
Code:
function isEven(num) {
return num % 2 === 0 ? "Even" : "Odd";
}
[Link](isEven(10)); // Even
[Link](isEven(7)); // Odd
Output:
Even
Odd
📸 Screenshot of output here
2. Arrow function to print your name 5 times
Code:
const printName = (name) => {
for (let i = 0; i < 5; i++) {
[Link](name);
}
};
printName("Habith Khan");
Output:
Habith Khan (printed 5 times)
📸 Screenshot of output here
3. Function to get string and change case
Code:
function changeCase(str) {
[Link]("Uppercase:", [Link]());
[Link]("Lowercase:", [Link]());
}
changeCase("FrontendDeveloper");
Output:
Uppercase: FRONTENDDEVELOPER
Lowercase: frontenddeveloper
📸 Screenshot of output here
4. Function to find factorial
Code:
function factorial(n) {
let fact = 1;
for (let i = 1; i <= n; i++) {
fact *= i;
}
return fact;
}
[Link]("Factorial of 5:", factorial(5));
Output:
Factorial of 5: 120
📸 Screenshot of output here
5. Function to count vowels
Code:
function countVowels(str) {
let vowels = "aeiouAEIOU";
let count = 0;
for (let ch of str) {
if ([Link](ch)) {
count++;
}
}
return count;
}
[Link]("Vowel count:", countVowels("Frontend Developer"));
Output:
Vowel count: 6
📸 Screenshot of output here
6. Insert new element in array & delete last
Code:
let a1 = [23, 45, 89, 22, 77, 9];
[Link](100);
[Link]("After adding:", a1);
[Link]();
[Link]("After deleting last:", a1);
Output:
After adding: [23,45,89,22,77,9,100]
After deleting last: [23,45,89,22,77,9]
📸 Screenshot of output here
7. Multiplication table of 8
Code:
function tableOf8() {
for (let i = 1; i <= 10; i++) {
[Link](`${i} x 8 = ${i * 8}`);
}
}
tableOf8();
Output:
1x8=8
...
10 x 8 = 80
📸 Screenshot of output here
8. Replace text in string
Code:
let text = "I am a front end developer";
let newText = [Link]("front end", "Full Stack");
[Link](newText);
Output:
I am a Full Stack developer
📸 Screenshot of output here
9. Function to check divisible by 6
Code:
function isDivisibleBy6(num) {
return num % 6 === 0 ? "Divisible by 6" : "Not Divisible by 6";
}
[Link](isDivisibleBy6(12));
[Link](isDivisibleBy6(25));
Output:
Divisible by 6
Not Divisible by 6
📸 Screenshot of output here
10. Print today’s date
Code:
function printDate() {
let today = new Date();
[Link]("Today’s date is:", [Link]());
}
printDate();
Output:
Today’s date is: Tue Sep 10 2025 (example)
📸 Screenshot of output here