1. Fill in the blanks.
a.The__________box is used to display information to the user.
b. A___________ is a storage area where value is stored and retrieved when required.
c. The_________operator finds out the remainder.
d. The__________operator is a unary operator.
e. The___________operator uses ? (question mark) and : (colon) characters.
Answer:-
a. alert
b. variable
C. modulus
d. I
e. conditional
2. Write T for True statement and F for False one, Correct the false statement(s),
a. The semicolon at the end of simple statements in JavaScript is mandatory.
b. In JavaScript MARKS and marks are treated as the same variable.
c. A simple statement must be enclosed in braces.
d. A compound statement consists of several instructions grouped in a block.
e. The switch statement can only be used to compare an expression against constans.
Answer:-
a. F
b. F
c. F
d. T
e. T

3. Multiple Choice Questions.
a. Which one is an invalid variable name in JavaScript?
i.Termployeename ii. Employeename iii. Employee_Narme iv. EmployeeName
b. A block of statements is enclosed within
i.() ii. {} iii.[] iv.””
C. The statement used to exit from the switch…case statement is
i, goto ii. break iii. continue iv. exit
d._____________takes a number as input from the user.
i. Alert message ii. Prompt dialog box iii. Confirm dialog box iv.All of these
e. Which one of these is not an arithmetic operator in JavaScript?
i.* ii.^ iii.+ iv./
f.== is a/an
i. Arithmetic operator
ii. Relational operator
iii. Compound Assignment operator
iv. Logical operator
Answer:-
a. 1employeename
b. {}
C. exit
d. Prompt dialog box
e. /
f. Relational operator

4. Short answer questions.

a. What are the three data types in Javascript?
Ans: The three data types in javascript are:-
(i)Numbers. Eg:- 453, 98.12 etc.
(ii)String. Eg:- “Grade”, etc.
(ii)Boolean. Eg:- True or False.

b. How will you declare variables sub1, sub2, and sub3 in Javascript?
Ans: We can declare variables sub1, sub2, and sub3 in Javascript as

var sub1, sub2, sub3.

c. Name the different forms of if statement.
Ans: The different forms of if statement are:-
(i)if statement.
(ii)if…else statement.
(iii)if..else if statement

d. Name the three logical operators.
.
Ans: The three different logical operators are:-
(i)&&(AND) operator.
(ii)II(OR) operator.
(iii)!(NOT) operator.

e. Write the statements equivalent to A++ and A–.
Ans: The statements equivalent to A++ and A– are Increment operator and Decrement
operator.

f. Write the statement form for the following:
A = A+15
B = B + 1
Ans: A+=15
B+=1

5. Long answer questions

a. Explain the two types of comments in Javascript.
Ans: The two types of comments in Javascript are:-
(i)Single line comment:- It starts with a pair of slash sign (//). The browser ignores anything from the pair of slash (//) till the end of that same line. Eg:- // Single line comment.
(ii) Multi-line comment:-It includes more than one line between /* and */ characters. The browser ignores the statement between these characters. It is also known as block comment. Eg:-/* This is a block

comment */

b. What are the rules of naming a Javascript variable?
Ans: The rules of naming a Javascript variable are:-
(i) The name must begin with a letter or the underscore character. It should not start with a digit. The first character is followed by letters, digits or underscore sign.
(ii)It should not be a reserved word.
(ii)We cannot have spaces in a variable name.
(iv)Javascript is case sensitive. Thus, for example, name, NAME and Name are treated as three different variables.

c. What are the limitations of switch statement?
Ans: The limitations of switch statement are:-
(i)The case label cannot be a variable. For eg:- case n: where n is a variable.
(ii)The case label cannot be a range. For eg:- case(1..3): .This is not a valid constant.

d. What is the difference between simple and compound statement?
Ans: A simple statement consists of a single instructions . It does not require braces to enclose it. A compound statement consists of several instructions grouped in a block. Such statements must be enclosed in braces if we wish to treat them all as a single statement.

e. Explain the working of conditional operators with an example.
Ans: The conditional operator evaluates an expression and returns the value written after ‘?’ if the condition evaluated is true. In case the result is false, the value after ‘:’ is returned. Its general format is: var result = condition? “TRUE”: “FALSE”;

Example:- We set a value for the variable ‘age’ as 20. The condition, whether age is greater than 18 is tested. If it results in true, the text after the question mark gets placed in the result variable. If the result is false, the text after the colon will be placed in the result variable.

APPLICATION BASED QUESTION:

1.Jasmine has written the given code to display a message box on the screen, but the message box is not showing on the screen. Find the problem in this code and rewrite it to display the given statement in message box.

Ans:-

<!DOCTYPE html >
<html>
<body><h1>SEBAHELP.COM</h1></body>
<script>
alert(" This is my first javascript code")
</script>
</html>

2.Rewrite the following code using if…else if statement.

case “N” : a = “North”; break;
case “E” : a = “East”; break;
case “W” : a = “West”; break;
case “S” : a = “South”; break;

Ans:-

<html>
<body><h1>SEBAHELP.COM</h1></body>
<script>
 x= prompt("Enter Code- N/E/W/S")
if (x=="N") { 
document.write (" North")
} 
else if (x=="E") { 
document.write ("EAST")
} 
else if (x=="W") { 
document.write (" WEST")
} 
else if (x=="S") { 
document.write ("SOUTH+")
} 
else {
document.write ("Enter correct code")
}
</script>
</html>

3.What will be the output of following code:

var a, b
a= 5
b= 10
b+= a
a++
b–
document.write(“a = “+ a + “<br>”)
document.write(“b = ” + b )

Ans:-

<html>
<body><h1>SEBAHELP.COM</h1></body>
<script>
var a, b
a= 5
b= 10
b+= a
a++
b--
document.write("a = "+ a + "<br>")
document.write("b = " + b )
</script>
</html>

Output:

introduction to javascript
introduction to javascript

4. Evaluate the following arithmetic expression and find out its output,assuming b=4 and c=4.

a=b*3/4+c/4+8-b+5/8

Ans:-

<html>
<body><h1>SEBAHELP.COM</h1></body>
<script>
var a, b,c
b=4
c=4
a=b*3/4+c/4+8-b+5/8
document.write("a = "+ a + "<br>")
</script>
</html>

OUTPUT:-

introduction to javascript Q4
introduction to javascript Q4

5. Assuming A=5 and B=6,what will be the result of the following statements:

i.((A!= B)&& (A>=B))

<html>
<body><h1>SEBAHELP.COM</h1></body>
<script>
var  A,B,C
A = 5
B = 6
C =((A!= B)&& (A>=B))
document.write("Output = "+ C+ "<br>")
</script>
</html>

Output:- FALSE

ii.(A!= B)|| (A<=B)

<html>
<body><h1>SEBAHELP.COM</h1></body>
<script>
var A, B,C
A = 5
B = 6
C=(A!= B)|| (A<=B)
document.write("Output= "+ C + "<br>")
</script>
</html>

 

Output:- TRUE
iii.!(A>B)

<html>
<body><h1>SEBAHELP.COM</h1></body>
<script>
var  A,B
A = 5
B = 6
!(A>B)
document.write(!(A>B))
</script>
</html>

Output:-TRUE

6.Write the following if…esle statement using the conditional operator.

if (x == 100)
a= “x is 100”
else
a = “x is not 100”

Ans:-

<html>
<body><h1>SEBAHELP.COM</h1></body>
<script type= "text/Javascript">
var x , result
x = prompt("Enter Value")
result = x==100 ? "x is 100" : "x is not 100"
document.write(result)
</script>
</html>

LEAVE A REPLY

Please enter your comment!
Please enter your name here