Previous Exam - Jordan University of Science and Technology

advertisement
First Semester
Jordan University of Science and Technology
Information Systems Department
CIS (340) Web Application Development
First Exam
Date: 16/3/2015
Std_Name:
Std_Number:
Instructor Name:
Section:
Serial#.:
Part1: write the output for the following code assume it write inside <script> tag [7 PTs]
A. List item 1
var a,b;
var choice=1;
switch ( choice )
{ case "1":
a = "<ol style = 'list-style-type: lower-alpha'>";
b = "</ol>";
default:
a = "<ol style = 'list-style-type: upper-alpha'>";
b = "</ol>";
break;
}
B. List item 2
C. List item 3
document.writeln( a );
for ( var i = 0; i <= 2; ++i )
document.writeln( "<li>List item " + i + "</li>" );
document.writeln( b );
4
var a = new Array( "CIS201", "CIS340","CIS340" );
var b = [ 2, 4, 6, 8,4,5 ];
var c = [ 2, , , 8 ];
document.write("<h1>"+c.length +"</h1>");
document.write("<h1>"+b.lastIndexOf(4)+"</h1>");
document.write("<h1>"+a.join("**")+"</h1>");
document.write("<h1>"+a.indexOf("cis34")+"</h1>");
1
4
CIS201**CIS340**CIS340
-1
CIS 340 First Exam
Part2: write a JavaScript code for the following case [6-PTs]
Consider the following HTML page with an incomplete JavaScript and HTML code, complete the page so:
1) Ask the user a positive number using FORMS
2) When the user click (press) the button print out “valid numeric value” in green message if enter a
positive numeric value otherwise print” invalid numeric” value in red message.Sample run:
<html><head><script>
function start()
{ var A=document.getElementById("B1");
A.addEventListener("click",Validate,false);
}
function Validate()
{var out="";
var T= parseInt(document.getElementById("T").value);
if(isNaN(T))
out+="<p style='color:red'>Invalid numeric value</p>";
else
out+="<p style='color:green'>valid numeric value</p>";
/*Student can use the isFinite function
if(isFinite(T))
out+="<p style='color:green'>valid numeric value</p>";
else
out+="<p style='color:red'>Invalid numeric value</p>";
*/
document.getElementById("D2").innerHTML=out;
}
window.addEventListener("load",start,false); </ script></head><body >
<h2>Enter Number then press button to validate </h2>
<form method="post" action="#">
<p>Value to validate <input type="text" id="T"></p>
<p><input type="button" id="B1" value="Submit"></p>
<div id="D2"></div>
</form></body>
2
CIS 340 First Exam
Part 3[7-pts]: Suppose we have the following images [sunday.gif, Monday.jpg, Tuesday.gif, Friday.png],
and the following list of quotes [“Life is short”, “to be or not to be”, “Actions speak louder than words”,” Willing
is not enough, we must do”].
- Design a webpage using (HTML/JAVASCRPIT) so that when the page load different random image
and quotes will show in each time the user visit the page:
<script>
function str(){
var pic=["sunday.gif","Monday.jpg","Tuesday.jpg","Friday.png"];
var qts=["Life is short","to be or not to be","Willing is not enough, we must
do","Actions speak louder than words"];
var p = document.getElementById("p");
var q = document.getElementById("q");
var i = Math.floor(Math.random()*4);
p.setAttribute("src",pic[i]);
q.innerHTML=qts[i]+pic[i];
}
window.addEventListener("load",str,false);
</script>
<body>
<img id="p" src="1.jpg" alt="flower">
<div id="q"></div>
</body>
3
CIS 340 First Exam
Download