0% found this document useful (0 votes)
13 views2 pages

webbased database assignment 2 solution

The document outlines Assignment No. 02 for the CS406 course, due on January 6, 2025, and consists of two programming tasks in JavaScript. The first task requires writing a program to determine if a user-inputted number is even or odd and calculate its square or cube accordingly. The second task involves counting and displaying the number of vowels in a user-inputted string.

Uploaded by

Mahiraa Shahzadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

webbased database assignment 2 solution

The document outlines Assignment No. 02 for the CS406 course, due on January 6, 2025, and consists of two programming tasks in JavaScript. The first task requires writing a program to determine if a user-inputted number is even or odd and calculate its square or cube accordingly. The second task involves counting and displaying the number of vowels in a user-inputted string.

Uploaded by

Mahiraa Shahzadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment No.

02 Total Marks: 15
Fall 2024 Due Date: 06-Jan-2025
FAIQA SHAHZADI
CS406 – Web Based Database Applications (BC230209196)

Topics Covered:

 Module 124 - 132


Problem Statement: Marks: 15

Questions No.1: (10 Marks)


Write a JavaScript program to solve the following tasks:
1. Ask the user to input a number.
2. Check whether the number is even or odd.
3. If the number is even, calculate and display its square. If it is odd, calculate and display its cube.

Solution:
// Ask the user to input a number
let number = parseInt(prompt("Enter a number:"));

// Check if the number is even or odd


if (number % 2 === 0) {
// If even, calculate and display its square
let square = number * number;
alert("The number is even. Its square is: " + square);
} else {
// If odd, calculate and display its cube
let cube = number * number * number;
alert("The number is odd. Its cube is: " + cube);
}

Questions No.2: (5 Marks)


Write a JavaScript program that performs the following steps:
1. Ask the user to input a string.
2. Count and display the number of vowels (a, e, i, o, u) in the string.
Solution:
// Ask the user to input a string
let inputString = prompt("Enter a string:");

// Define vowels
let vowels = "aeiouAEIOU";

// Initialize counter for vowels


let vowelCount = 0;

// Loop through the string and count vowels


for (let i = 0; i < inputString.length; i++) {
if (vowels.includes(inputString[i])) {
vowelCount++;
}
}
// Display the result
alert("The number of vowels in the string is: " + vowelCount);

Deadline: Your assignment must be uploaded on or before 06 January 2025. No solution will be accepted
through email after the due date.

You might also like