In this lab you will write two simple JavaScript programs based on examples on this page.
story.html
on your Desktop.
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>
A story program for CSci 1001
</title>
</head>
<body>
<h1>A story program for CSci 1001</h1>
<p>
<script type="text/javascript">
// variables
var person = "Mary";
var place = "Morris";
// add more variables here:
document.write(person + " lives in " + place);
// continue the story here:
</script>
</p>
</body>
</html>
person
and
place
. Feel free to change the beginning. Check your
program after every change. Tools
and choose
JavaScript Console
. This is where the error messages are
displayed. Press Clear
to clear the old messages, then go
to the page again, and then bring up the console again, it shoudl show
you an error message for your program. Correct the mistake and try it
again.var person = "Mary";
to
var person = "Peter";
Reload your page, and see it change.temperature.html
.
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>
Celsius-to-fahrenheit conversion for CSci 1001
</title>
</head>
<body>
<h1>Celsius-to-fahrenheit conversion for CSci 1001</h1>
<p>
<script type="text/javascript">
var celsius = window.prompt("Please enter temperature in Celsius:", "");
var fahr = (celsius * 1.8) + 32;
document.write("The temperature is " + fahr + " Fahrenheit<br />");
// Add another prompt to ask for temperature in Fahrenheit,
// convert it to Celsius and print the result
// The conversion formula is C= (F-32)*0.5555
</script>
</p>
</body>
</html>
fahr
document.write
JavaScript
Console
This page is a part of CSci 1001 course web site.