Goal: Display a random item from an array of notable items.
var predictions = ["Signs point to yes.",
"Cannot predict now.",
"My reply is no."];
Look up Magic 8 Ball on Wikipedia to see all 20 predictions.var numItems = predictions.length;
var randomIndex = Math.floor(Math.random( ) * numItems);
return predictions[randomIndex];
Grading Breakdown: Functionality: 30, Creativity: 10, Source Code Comments: 5, Submitted Correctly: 5 (Include a header with your name, project number, and submit date.)
20 point deduction for using Magic
8-ball notable items.
20 point deduction for only 3 notable items instead of
8.
Goal: Display a list (ordered or unordered) of notable items in a localhost browser.
Important: you must create the Node project and install the http-status-codes module before you can test and submit Tutorial 2b.
C:\it231\tutorial2b-smith> npm initEnter main.js as the startup file.
C:\it231\tutorial2b-smith> npm install http-status-codes
const http = require("http");
const httpStatus = require("http-status-codes");
function processRequest(request, response) {
console.log("Received an incoming request.");
response.writeHead(httpStatus.StatusCodes.OK, {"Content-type": "text/html"});
var responseMessage = "<h1>Hello, World.</h1>";
response.write(responseMessage);
response.end( );
console.log("Sent this response message: " + responseMessage);
}
const server = http.createServer(processRequest);
server.listen(3000);
console.log("Server started and is listening on port 3000");
Start the project:C:\it231\tutorial2b-smith> node main.js
responseMessage += "<ol>";
for(var p of notableItems) {
responseMessage += `<li>${p}</li>`;
}
responseMessage += "</ol>"
Grading Breakdown: Functionality: 30, Creativity: 10, Source
code comments: 5, Source Code Headers: 2.5, Submitted Correctly: 2.5
Source code comments explain the lines of code that you submit for Tutorial 2b.
Source Code Headers are comments that contain your name, project number and submit date.
Submitted correctly means that you named your source code folder tutorial2b-smith or tut2b-smith
(replace tut2b with the actual tutorial or project number; replace smith with your last name.
Goal: Display a random item in the Node console.
response.write("<h1>Random Notable Item</h2>");
response.write(`<p>${chooseRandomItem( )}</p>`);
response.end( );
Grading Breakdown: Functionality: 30, Creativity: 10, Source
code comments: 5, Source Code Headers: 2.5, Submitted Correctly: 2.5
Don't forget to: