Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Q1

<html>
<body>
<script type="text/javascript">
var a=0,b=1,c;
document.write("Fibonacci");
while (b<=20)
{
document.write(c);
document.write("<br/>");
c=a+b;
a=b;
b=c;
}
</script>
</body>
</html>
Q2
(i)<html>
<body>

<script type="text/javascript">

var age = 15;

if( age > 18 ){


document.write("<b>Qualifies for driving</b>");
}

else{
document.write("<b>Does not qualify for driving</b>");
}

</script>

<p>Set the variable to different value and then try...</p>


</body>
</html>

(ii)<html>
<body>
<button onclick="myFunction()">Try it</button>
<br/>
<br/>Enter first number:
<input type="text" id="txt1" name="text1">Enter second number:
<input type="text" id="txt2" name="text2">
<script>
function myFunction() {
var y = document.getElementById("txt1").value;
var z = document.getElementById("txt2").value;
var x = y + z;
var d= y-z;
document.write(x);
document.write(d);
}
</script>
</body>
</html>

Q3
<html>
<body>

<script type="text/javascript">

var grade='A';
document.write("Entering switch block<br />");
switch (grade)
{
case 'A': document.write("Good job<br />");
break;

case 'B': document.write("Pretty good<br />");


break;

case 'C': document.write("Passed<br />");

break;

case 'D': document.write("Not so good<br />");


break;

case 'F': document.write("Failed<br />");


break;

default: document.write("Unknown grade<br />")


}
document.write("Exiting switch block");

</script>

<p>Set the variable to different value and then try...</p>


</body>
</html>

Q4
<html>
<head>
<script type="text/javascript">
function over()
{
document.write("Mouse Over");
}
function out()
{
document.write("Mouse Out");
}
</script>

</head>
<body>
<p> Bring your mouse inside the division to see the result:</p>
<div onmouse="over()"
onmouse="out()" >
<h2> This is inside the division </h2>
</div>
</body>
</html>
Q5
<html>
<head>
<script type="text/javascript">
function getvalue()
{
var retval=prompt("Enter your name:","your name here");
document.write("you have entered"+retval);
}
</script>
</head>
<body>
<p> click the following button to see the result:</p>
<form>
<input type="button" value="click me" onclick="getvalue();"/>
</form>
</body>
</html>

Q6
<html>
<head>
<script type="text/javascript">
var teststring = 'abcdedcba';
function IsPalindromeIteration(str){
var len = str.length, i=0, result = true;
if (len <= 1) return true;
while(i != len - i - 1){
var start = str.charAt(i),
end = str.charAt(len - i - 1);
if (start != end){
return false;
}
i++;
}
return result;
}

// res will have a value 'true'


var res = IsPalindromeIteration(teststring);
console.log('Is the string a palindrome ' + res);
</script>
</body>
</html>

You might also like