- What is the difference between the JavaScript statements
let n = 329;
and the statement
var n = 329;
Answer: A variable defined using var is valid in the function where it
is defined. A variable defined using let is only valid in the block
where it is defined. (A block consists of lines code enclosed in
curly braces. Here are some examples:
{
var n = 123;
}
console.log(n);
// Output:
123
{
let m = 123;
}
console.log(m);
Uncaught ReferenceError: m is not defined.
- What does the nodemon package do?
Answer: The nodemon package automatically restarts the node
server when a change is made to the main.js script.
- What does the Node command npx do?
Answer: it executes a Node package.
- What do these Express response methods do?
send render
Answer: send sends a string to the browser,
sendFile sends the contents of an HTML file to the
browser,
render sends the contents of an EJS file
from the views folder to the browser.
- What does the file extension .ejs mean?
Answer: Embedded JavaScript.
- Write a hyperlink that selects the /specials route. Answer:
<a href="/specials">Specials</a>
- Write an image element that displays the image eiffel-tower.jpg on an HTML or EJS page.
This image is located in the static folder public/images. Answer:
<img src="/images/eiffel-tower.jpg" alt="Eiffel Tower">
- Write a link tag that links the current page to the external style sheet
styles.css located in the
static folder public/css. Answer:
<img src="/images/eiffel-tower.png" alt="Eiffel Tower">
- MeetTheFlintstones1 Example. The following source code files have errors. Fix the errors and use these
files to implement the Express project meet-the-flintstones. Place these images
in the folder public/images: fred.jpg and
wilma.jpg.
----- Source code file: main.js -------------------------
<!DOCTYPE html>
const express = import("express");
const path = require("path");
const app = express;
app.use(express.public("static"));
app.get("/fred", (r, q) => {
res.render("fred.ejs");
});
app.post("/wilma", (q, r) => {
q.render("views/wilma);
});
app.listen(3000, ( ) -> {
console.log("Server started; listening on port 3000");
);
----- Source code file: views/fred.ejs -----------------
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Meet Fred Flintstone<title>
<link ref="stylesheet" src="css/styles.css">
</head>
<body>
<h1>Meet Fred Flintstone</h1>
<img href="images/wilma.jpg"><br><br>
<a src="fred">Meet Fred Flintstone</a>
</body>
</html>
----- Source code file: views/wilma.ejs ----------------
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Meet Wilma Flintstone</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Meet Wilma Flintstone</h2>
<img src="image/wilma.png"><br><br>
<a href="\fred">Meet Fred Flintstone</a>
</body>
</html>
----- Source code file: public/css/styles.css -----------
body { backgroundColor: E0E0FF;
color: #000000;
font: 100% verdana san-serif; }
h1 { color: #000080;
img { width: 150; height: 200; )
---------------------------------------------------------
Answer: Here are the corrected
meet-the-flintstones files.