Вы находитесь на странице: 1из 3

Answer the following questions based on JavaScript:

1. With the help of suitable example, explain two points of difference between global

and local variables.

2. Give the output of the following set of statements:


<SCRIPT LANGUAGE="JavaScript">
var num = [4];
var con = 0;
for (i= 3; i>=0; i--)
{
num[i]= i * con;
document.write(num[i]+ “<br>”);
con = con + 1;
}
</script>

3. Rewrite the above code using while loop without affecting the output.

<SCRIPT LANGUAGE = “JavaScript”>

var num = [4] ;

var con = 0 ;

i = 3;

do

num [i] = i * con;

Document.write (num [i] + “<br>”) ;

con = con + 1;

i-- ;

} while (i>=0)

</script>

4. Create a form that contains a Tax Calculator as shown below. When the user enters his
salary, the tax to be paid should be displayed in the second textbox.
The calculation of tac should be done as follows:
If the salary is greater than or equal to 200000, then the tax should be 10% of the
salary.
If the salary is greater than or equal to 100000 but less than 200000, then the tax
should be 5% of the salary.
And if the salary is less than 100000, then no tax.
Write the HTML code for creating the form and the embedded JavaScript code for the
click event of the button.
5. Give the output of the following set of statements:
<SCRIPT LANGUAGE="JavaScript">
var car[3];
count = 0;
for(i = 2; i>=0;i--)
{
car[i] = i + count;
document. write (car[i]);
count = count + 1;
}
</SCRIPT>
6. Rewrite the above code using do-while-loop without effecting the output
7. Create a form that contains a list of mail services as shown below
Select a location from the list

Write the HTML code for creating the form and the embedded JavaScript code to open
the corresponding website in a new window on the selection of any list item.
Go to Yahoo!! Link to http://www.yahoo.com
Go to Hotmail!! Link to http://www.hotmail.com
Go to Rediff!! Link to http://www.rediff.com

8. Answer the following questions based on JavaScript:


a) Observe the code segment given below and answer the questions that follow:
<SCRIPT LANGUAGE= "javascript">
var A,B,C;
A = (10*3)%(4/2);
B = 40%3;
if(!(B >= A))
C = 5;
else
C = 10;
</SCRIPT>
a) Name any one relational operator and one logical operator used in the above code
segment
b) Rewrite the statement : if(!(B >= A))without using the ! operator

9. A code to display the no. of characters of a string is written below. Fill in the blank to

complete it:
<script language=”javascript”>
var sometext = “Bye!”
document.write(_____________(sometext))
</script>

10. Give the output of the following code segment:

<SCRIPT LANGUAGE="JavaScript">
var sum, a;
sum = 0;
a = 1;
do
{
sum = sum + a;
a = a+2;
}while(a<=8)
document.write(sum);
</SCRIPT>

Вам также может понравиться