0% found this document useful (0 votes)
30 views

Var A 0, B 1, C Document - Write ("Fibonacci") While (B ") C A+b A B B C )

The document contains 6 questions with HTML/JavaScript code snippets. Q1 prints the Fibonacci sequence up to 20. Q2 contains code to check if a user is eligible to drive based on their age input, and code to add/subtract two numbers input by the user. Q3 uses a switch statement to print different messages based on the grade variable input. Q4 prints messages when the mouse is over or out of a division. Q5 prompts the user for their name and prints it. Q6 contains a function to check if a string is a palindrome by iterating through the characters.
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)
30 views

Var A 0, B 1, C Document - Write ("Fibonacci") While (B ") C A+b A B B C )

The document contains 6 questions with HTML/JavaScript code snippets. Q1 prints the Fibonacci sequence up to 20. Q2 contains code to check if a user is eligible to drive based on their age input, and code to add/subtract two numbers input by the user. Q3 uses a switch statement to print different messages based on the grade variable input. Q4 prints messages when the mouse is over or out of a division. Q5 prompts the user for their name and prints it. Q6 contains a function to check if a string is a palindrome by iterating through the characters.
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/ 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