// Example 1
// Use 5 paragraphs in HTML file.
$(function( ) {
$("p").click( function( ) {
$(this).hide( );
});
});
// Example 2
// Use buttons with captions "Hide" and "Show",
// and also a paragraph with no ID.
$(function( ) {
$("#hide").click(function( ) {
$("p").hide( );
});
$("#show").click(function( ){
$("p").show();
});
});
// Example 3
// Use 3 input elements with type="text".
$(function( ) {
$("input").focus(function( ) {
$(this).css("background-color", "#cccccc");
});
$("input").blur(function( ){
$(this).css("background-color", "#333333");
});
});
See the W3Schools site for the complete HTML files, which can be run interactively. Here are
the HTML files with scripts (jQuery and
Vanilla JS) that we looked at in class.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>MathRiddles1 Example</title>
</head>
<body>
<ol>
<li><span id="r1">
Why is 6 scared of 7?</span><br>
<span id="a1">
Because 7 8 9.</span>
<button>Show Answer for Riddle 1</li>
<li><span id="r2">
How can you tell that the three fractions
x/c, y/c, and z/c all live in a foreign country?</span><br>
<span id="a2">
Because they are all over cs.</span>
<button>Show Answer for Riddle 2</li>
<li><span id="r3">
What did the repeating decimal number say to pi?</span><br>
<span id="a3">
Don't be so irrational.</span>
<button>Show Answer for Riddle 3</li>
</ol>
</body>
</html>
The each answer is hidden, but can be displayed when the button for
its riddle is clicked.const correctAnswers = ["b", "c", "a"];Start with this HTML code for an ordered list:
<ol>
<li>First Question.<br>
<ol>
<li><input type="radio" id="11" name="q1" value="a">
Answer A.</li>
<li><input type="radio" id="12" name="q1" value="b">
Answer B.</li>
<li><input type="radio" id="13" name="q1" value="c">
Answer C.</li>
</ol>
</li>
<li>Second Question.<br>
<ol>
<li><input type="radio" id="21" name="q2" value="a">
Answer A.</li>
<li><input type="radio" id="22" name="q2" value="b">
Answer B.</li>
<li><input type="radio" id="23" name="q2" value="c">
Answer C.</li>
</ol>
</li>
<li>Third Question.<br>
<ol>
<li><input type="radio" id="31" name="q3" value="a">
Answer A.</li>
<li><input type="radio" id="32" name="q3" value="b">
Answer B.</li>
<li><input type="radio" id="33" name="q3" value="c">
Answer C.</li>
</ol>
</li>
</ol>
<button id="btn1">Compute Score</button>
<p id="numcorrect"></p>
Answer: Here are the complete HTML, CSS, and JavaScript files:
==================================================
<!DOCTYPE html>
<!-- Source code file: index.html -->
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="styles.css">
<script src="script.js"></script>
</head>
<body>
<ol>
<li>First Question.<br>
<ol>
<li><input type="radio" id="11" name="q1" value="a">
Answer A.</li>
<li><input type="radio" id="12" name="q1" value="b">
Answer B.</li>
<li><input type="radio" id="13" name="q1" value="c">
Answer C.</li>
</ol>
</li>
<li>Second Question.<br>
<ol>
<li><input type="radio" id="21" name="q2" value="a">
Answer A.</li>
<li><input type="radio" id="22" name="q2" value="b">
Answer B.</li>
<li><input type="radio" id="23" name="q2" value="c">
Answer C.</li>
</ol>
</li>
<li>Third Question.<br>
<ol>
<li><input type="radio" id="31" name="q3" value="a">
Answer A.</li>
<li><input type="radio" id="32" name="q3" value="b">
Answer B.</li>
<li><input type="radio" id="33" name="q3" value="c">
Answer C.</li>
</ol>
</li>
</ol>
<button id="btn1">Compute Score</button>
<p id="numcorrect"></p>
</body>
</html>
--------------------------------------------------
/* Source code file: styles.css */
ol ol { list-style-type: lower-alpha; }
--------------------------------------------------
// Source code file: script.js
function computeScore( ) {
const correctAnswers = ["", "b", "c", "a"];
var numCorrect = 0;
for(var i = 1; i <= 3; i++) {
for(var j = 1; j <= 3; j++) {
var rb = document.getElementById("" + i + j);
if (rb.checked && rb.value == correctAnswers[i]) {
numCorrect++;
}
}
}
var outputPara = document.getElementById("numcorrect");
outputPara.innerHTML = "Number correct: " + numCorrect;
}
function init( ) {
var button1 = document.getElementById("btn1");
button1.addEventListener("click", computeScore);
}
window.addEventListener("load", init);
==================================================
var d = new Date( ); document.writeln(d); // Output: Sun Feb 21 2021 10:11:22 GMT-0600 (Central Standard Time)
var d = new Date(1978, 2, 18); document.writeln(d); // Output: Sat Mar 18 1978 00:00:00 GMT-0600 (Central Standard Time)
var d = new Date(1978, 2, 18); document.writeln(d); // Output: Sat Mar 18 1978 23:59:58 GMT-0600 (Central Standard Time)
var d = new Date( );
var yr = d.getFullYear( );
var mon = d.getMonth( );
var day = d.getDate( );
var hr = d.getHours( );
var min = d.getMinutes( );
var sec = d.getSeconds( );
document.writeln(`${yr} ${mon} ${day} ${hr} ${min} ${sec}`);
// Output: 2021 1 21 10 31 56
var d = new Date( ); document.writeln(d.getTime( ));
var d = new Date(1970,0,1); document.writeln(d.getTime( )); // Output: 21600000
studentweb.cdm.depaul.eduis
216.220.181.34
GET /test.txt http/1.0The response would look something like this:
HTTP/1.1 302 Found Date: Thu, 19 Feb 2021 02:50:55 GMT Server: Apache/2.0.53 HP-UX-Apache-based_Web_Server (Unix) PHP/4.3.8 Last-Modified: Tue, 27 Oct 2015 14:39:09 GMT ETag: "16896-61d-408dd700" Accept-Ranges:Bytes Content-Length: 18 Connection: close Content-Type: text/html Content: This is a test.
PS C:\Users\sjost> Invoke-WebRequest facweb.cdm.depaul.edu/sjost/test.txt
StatusCode : 200
StatusDescription : OK
Content : This is a test.
RawContent : HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 18
Content-Type: text/plain
Date: Fri, 19 Feb 2021 20:50:26 GMT
ETag: "6590583dc510d11:0"
Last-Modified: Tue, 27 Oct 2015 14:39:09 GMT
Serve...
Forms : {}
Headers : {[Accept-Ranges, bytes], [Content-Length, 18],
[Content-Type, text/plain], [Date, Fri,
19 Feb 2021 20:50:26 GMT]...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : mshtml.HTMLDocumentClass
RawContentLength : 18
> curl -v http://facweb.cdm.depaul.edu/sjost/test.txtYou should get output something like this:
* Trying 216.220.181.39:80... * TCP_NODELAY set * Connected to facweb.cdm.depaul.edu (216.220.181.39) port 80 (#0) > GET /sjost/test.txt HTTP/1.1 > Host: facweb.cdm.depaul.edu > User-Agent: curl/7.68.0 > Accept: */* > * Mark bundle as not supporting multiuse < HTTP/1.1 200 OK < Content-Type: text/plain < Last-Modified: Tue, 27 Oct 2015 14:39:09 GMT < Accept-Ranges: bytes < ETag: "6590583dc510d11:0" < Server: Microsoft-IIS/10.0 < X-Powered-By: ASP.NET < Date: Mon, 02 Oct 2023 00:25:08 GMT < Content-Length: 18