0% found this document useful (0 votes)
114 views6 pages

Js Answer Paper

Hi am study diploma in Computer engineering and technology and technology and technology

Uploaded by

sayedshaad02
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)
114 views6 pages

Js Answer Paper

Hi am study diploma in Computer engineering and technology and technology and technology

Uploaded by

sayedshaad02
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/ 6

Answer pepper of JavaScript

2Marks

Q1)What are arithmetic and logical operator used in JS.


Ans):-
 Arithmetic Operators: +, -, *, /, % (modulus), ++
(increment), -- (decrement)
 Logical Operators: && (AND), || (OR), ! (NOT).

Q2) How will you define a function in JavaScript?


Ans:- Define a function in JavaScript using the function
keyword:
Function functionName() {
// code to be executed
}

Q3) What is a ternary operator with syntax?


Ans:- The ternary operator is a shorthand for an if-else
statement.
Syntax: condition ?
expressionIfTrue :
expressionIfFalse;

Q4) Differentiate between prompt() and alert() methods


Ans:-
 Prompt(): Used to get input from the user. It returns the
user’s input as a string.

 Alert(): Used to display a message in a pop-up dialog box.


It doesn’t return anything.

Q5) . Write JS to display the first 20 even numbers on the


document window.
Ans:-
For (let I = 1; I <= 40; i++) {
If (I % 2 === 0) {
Document.write(I + “ “);
}
}
4Marks

Q1) Write a JavaScript function to count the number of


vowels in a given string.
Ans:-
Function countVowels(str) {
Let count = 0;
Const vowels = ‘aeiouAEIOU’;
For (let char of str) {
If (vowels.includes(char)) {
Count++;
}
}
Document.write(“Number of vowels in the string: “ + count);
}

Q2)Generate a college admission form using the HTML


form tag.
Ans:-
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8”>
<meta name=”viewport” content=”width=device-width,
initial-scale=1.0”>
<title>College Admission Form</title>
</head>
<body>

<h2>College Admission Form</h2>

<form action=”/submit_admission” method=”POST”>


<label for=”name”>Name:</label>
<input type=”text” id=”name” name=”name”><br><br>

<label for=”dob”>Date of Birth:</label>


<input type=”date” id=”dob” name=”dob”><br><br>

<label for=”email”>Email:</label>
<input type=”email” id=”email” name=”email”><br><br>

<label for=”course”>Course:</label>
<select id=”course” name=”course”>
<option value=”computer_engineering”>Computer
Engineering</option>
<option value=”mechanical_engineering”>Mechanical
Engineering</option>
<option value=”civil_engineering”>Civil
Engineering</option>
</select><br><br>

<input type=”submit” value=”Submit">


</form>

</body>
</html>
Q3)Write JS to convert a string to a number.
Ans:-

Let str = ‘123’;


Let num = Number(str);
Document.write(“The converted number is: “ + num);

Q4)Write a JavaScript conditional statement to sort three


numbers. Display an alert box to show the result.
Ans:-
Function sortThreeNumbers(a, b, c) {
Let numbers = [a, b, c];
Numbers.sort((x, y) => x – y);
Alert(“Sorted numbers: “ + numbers.join(“, “));
}

sortThreeNumbers(5, 2, 8);

You might also like