What is a stub page?
Answer: a stub page is a placeholder the actual page (in this case your proj1a or proj1b index.html
page. The stub page is used to check if the hyperlinks from the Project 0 index page to the stub page
and from the stub page back to the Project 0 index page work. These stub pages will be replaced
when Project 1a and 1b are completed.
What is an entity? What are some common HTML entities that you know?
Here is a reference that contains the complete list of HTML entities:
https://www.freeformatter.com/html-entities.html.
Answer: here are some commonly used entities:
Entity Meaning
====== =======
< <
> >
& &
Non-breaking space
" "
' '
α α
β β
γ γ
Δ Δ
The HTML pages page1.html and
page2.html are stored on the server
in this directory structure:
Add a link to page1.html with target page2.html.
Show Page 2 in a new window.
Add a link to page2.htm with target page1.htm.
Show Page 1 in a new window.
Ans: Here is a zipfile of these folders and files:
foldera.zip.
You upload your Project 0 to the studentweb server and
try to view it in a browser using this URL:
http://studentweb.cdm.depaul.edu/ssmith/index.htm
However, you obtain this message:
Not Found
The requested URL /~ssmith/index.htm was not found on this server.
What might be wrong?
Answer: You might not have uploaded your files to the public_html folder. Perhaps you
misspelled a folder or file name, for example, maybe index.htm is spelled as
index.html.
What is wrong with this address element:
<a href="/target.html">Go to Target Page</a>
Answer: a relative URL should not start with a slash (/); it
should just be href="target.html".
What do these four shortcut styles do?
td { padding: 5px 10px 15px 20px; }
Answer: 5 pixels padding on top;
10 pixels padding on the right;
15 pixels padding on the bottom;
20 pixels padding on the left.
(The amount of padding specified starts
at the top and goes around clockwise.)
td { padding: 5px 10px 15px; }
Answer: 5 pixels padding on top;
10 pixels padding on the left and right;
15 pixels padding on the bottom.
td { padding: 5px 10px; }
Answer: 5 pixels padding on the top and bottom;
10 pixels padding on the left and right.
td { padding: 5px; }
Answer: 5 pixels padding on all sides.
How you define a textfield that looks like this?
Answer:
<input type="text">
Here are some of the other type attribute values:
button checkbox color date datetime-local email
file hidden image month number password radio
range reset search submit tel time url week
Practice Quiz
Take PracticeQuiz2a.
What is JavaScript?
In September 1995 JavaScript was created in 10 days by Brendan Eich of
Netscape Communications.
It is a lightweight scripting language, used to build websites -- about 1.52
billion of them, 95% of all websites.
Originally, the name of JavaScript was Mocha. It was designed as a web
scripting companion to Java.
The name Mocha was changed to LiveScript for marketing purposes.
In 1998, AOL acquired Netscape and formed an alliance with Sun Microsystems
to develop web software. At that time that the name of LiveScript was
changed to JavaScript. This was a marketing ploy, based on the popularity of Java.
JavaScript and Java are very different, but the two languages have many
syntax elements in common.
ECMAScript (starting in 1997) is a standard for JavaScript, which is meant
to ensure the interoperability of web pages across different browsers. ECMA
means European Computer Manufacturers Association.
Using the Chrome Browser, click on the three dots icon in the upper right
corner; Select More tools >> Developer tools. In the HTML code
for Item 1, replace the line
document.writeln("Hello, World.");
with
console.log("Hello, World.");
Refresh the browser.
Writing to the browser console is useful for debugging.
Display a popup window
In the HTML code for Item 1, use
alert("Hello, World.");
instead of
console.log("Hello, World.");
Display Output in a Textfield
You already know how to do this from IT 130. We will look
at other possibilities this later.
Functions
A function is a set of statements designed to perform a task.
A function must be called or invoked to execute the statements.
Test this function that converts a length from inches
to centimeters:
// BasicFunction Example
// Function definition:
function inToCm(inches) {
cm = inches * 2.54;
return cm;
}
// Function test:
var inches = prompt("Enter length in inches", "0");
var cm = inToCm(inches);
document.writeln("Length in cm: " + cm);
// If input is 2, the output is 5.08
Why are the outputs on the same line?
I thought that writeln puts a newline
character (\n) at the end of its output. Place these statements
in this test script before viewing the HTML page:
<html>
<body>
<script>
// Copy JavaScript code to test here.
</script>
</body>
</html>
Place a button on a web page that looks like this:
The button should display the text "I've been clicked." when the button is clicked.
Give three solutions: (a) using an onclick attribute in the
<button> tag,
(b) using the addEventListener method in an init method,
(c) and setting the onclick
Answer: here is the source code,
including HTML code and JavaScript code, using the
property of the button object that represents the button tag.
Separate the code for this example into separate HTML, CSS, and JavaScript files:
<!DOCTYPE html>
<!-- Birthday Riddle Example -->
<html>
<head>
<title>Birthday Riddle</title>
<style>
body { background-color: #FFE0E0;
color: navy; font-family: verdana, sans-serif;
}
</style>
<script>
function showAnswer( ) {
var para = document.getElementById("p2");
para.innerHTML =
"Answer: December 31; today is January 1.";
}
</script>
</head>
<body>
<h1>Birthday Riddle</h1>
<p id="p1">Riddle: The day before yesterday I was 21,
and next year I will be 24. When is my birthday?</p>
<p id="p2"></p>
<input type="button" value="Show Answer"
onclick="showAnswer( )">
<body>
</html>
Answer:
---- index.html ----------------------
<!DOCTYPE html>
<!-- Birthday Riddle Example -->
<html>
<head>
<title>Birthday Riddle</title>
<link rel="stylesheet" href="styles.css">
<script src="script.js"></script>
</head>
<body>
<h1>Birthday Riddle</h1>
<p id="p1">Riddle: The day before yesterday I was 21,
and next year I will be 24. When is my birthday?</p>
<p id="p2"></p>
<input type="button" id="btn1" value="Show Answer">
<body>
</html>
---- styles.css ----------------------
/* BirthdayRiddle Example */
body { background-color: #FFE0E0;
color: navy; font-family: verdana, sans-serif;
}
---- script.js -----------------------
// BirthdayRiddle Example
function showAnswer( ) {
var para = document.getElementById("p2");
para.innerHTML =
"Answer: December 31; today is January 1.";
}
function init( ) {
var button = document.getElementById("btn1");
button.onclick = showAnswer;
// or
// button.addEventListener("click", showAnswer);
}
window.onload = init;
// or
// window.addEventListener("load", init);
--------------------------------------
Test Script
To test the JavaScript code for the rest of these notes, use this test script:
<!DOCTYPE html>
<html>
<body>
<script>
// Copy JavaScript code to test here.
</script>
</body>
</html>
JavaScript Datatypes
number -- JavaScript numbers are represented as 64 bit
(double precision) floating point numbers:
35342, -8976, 0, 34.3827, -1.359, 4.565e16, -9.37e-31
Try out this web page:
<!DOCTYPE html>
<!-- MaxValue Example -->
<html>
<body>
<script>
var n = 2;
// Repeat for loop 11 times.
for(var i = 1; i <= 11; i++) {
document.write(n + " ");
n = n * n;
}
document.writeln("<br><br>");
document.writeln(
"<br>Maximum Number Value:<br>" +
Number.MAX_VALUE + "<br>");
</script>
</body>
</html>
// Output:
2 4 16 256 65536 4294967296 18446744073709552000
3.402823669209385e+38 1.157920892373162e+77
1.3407807929942597e+154 Infinity
Maximum Number Value: 1.7976931348623157e+308
The special values Infinity and NaN are also values of the Number datatype.
Infinity is a numeric value that is larger that the largest legal
Number value, which is
1.7976931348623157e+308. The value NaN
is obtained from a numeric computation that does not produce a legal floating
point value.
string -- A string of characters delimited by
single or double quotes: 'dog', "horse", 'supercalifragilisticexpialidocious',
"243567", "!@#$%^&*()",
' ' (space), "" (null string)
boolean -- true or
false
undefined -- Special value assigned to a
variable that is
declared, but not yet assigned a value.
null -- Value assigned by the programmer to a
variable to show
that the variable has no value. Try out this statements in a script:
// Undefined Example
var s;
document.writeln(s + "<br>");
var t = null;
document.writeln(t + "<br>");
// Output:
undefined
null
Two additional Java datatypes that we will not discuss
are bigint and symbol.