Let quotes = [ 'It is a truth universally acknowledged, that a single man in posse 'I hate to hear you talk about all women as if they were fine ladie 'Silly things do cease to be silly if they are done by sensible pec "Give a girl an education and introduce her properly into the worlc 'Life seems but a quick succession of busy nothings.", 'Our scars make us know that our past was for real.", 'I cannot speak well enough to be unintelligible.", 'One cannot be always laughing at a man without now and then stumbl 'Men were put into the world to teach women the law of compromise." ITho be it gentlomon orr ady krho hac
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
Having trouble with this debugging. new quotes should be visible everytime page loads up.
![// Array of Jane Austen Quotes
let quotes = [
"It is a truth universally acknowledged, that a single man in possession of a good fortune, must be in want of a wife.",
"I hate to hear you talk about all women as if they were fine ladies instead of rational creatures. None of us want to be in calm waters all our lives.",
"Silly things do cease to be silly if they are done by sensible people in an impudent way.",
"Give a girl an education and introduce her properly into the world, and ten to one but she has the means of settling well, without further expense to anybody.",
"Life seems but a quick succession of busy nothings.",
"Our scars make us know that our past was for real.",
"I cannot speak well enough to be unintelligible.",
"One cannot be always laughing at a man without now and then stumbling on something witty.",
19
20
21
22
23
24
25
26
27
28
29
"Men were put into the world to teach women the law of compromise.",
30
"The person, be it gentlemen or lady, who has not pleasure in a good novel, must be intolerably stupid."
31
];
32
33
// Run the quote generator every time the page loads
window.addEventListener("load", quoteGenerator);
34
35
36
37
// Function to generate and display a random quote
function quoteGenerator() {
38
39
40
// Number of quotes in the array
quoteCount = quotes. length;
41
42
43
// Generate a random integer to select a quote
randomQuote = randomInt(0, quoteCount);
44
45
46
47
// Retrieve a randomly-selected quote
48
quotes = quotes[randomQuotes];
49
50
// Display the random quote
document.getElementByTagName("blockquote") [1].innerHTML = quotes;
51
52
53
}
54
55
56
57
58
59
60
61
62
/*:
// Function to return a randomly-selected integer between lowest and highest, inclusive
function randomInt(lowest, highest) {
63
64
65
let size = highest - lowest + 1;
return Math.floor(lowest + size*Math. random());
66
67
}](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F8f399ba7-b009-4644-8bcd-a13b6a8c4ed8%2Fd7c7995c-4984-4635-85ac-600aabd637c0%2Fzihph7p_processed.png&w=3840&q=75)
![5. Use the debugger to locate the syntax and runtime errors within the document. Fix the errors using your code
editor.
6. Once you have fixed the syntax and runtime errors, continually reload the web page. Each time the page is
loaded, a Jane Austen quote is randomly selected from the array. Occasionally, an undefined value appears
where the quote should be. Find the source of this logic error by setting a breakpoint at Line 48 and watch the
values of the randomQuote and quotes [randomQuote] expression. What are their values that result in an
undefined quote?
7. Return to the code editor and fix the program to remove the logic error. (Hint: What is the largest index in the
quotes array and what would happen if you tried to retrieve an entry larger that index?)
8. Return to the project04-02.html file in your browser and continually reload it to verify that the undefined quote
no longer appears.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F8f399ba7-b009-4644-8bcd-a13b6a8c4ed8%2Fd7c7995c-4984-4635-85ac-600aabd637c0%2Fxy3d54_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Required HTML and JavaScript file codes are provided below with comments in code.
Text format of code for the JavaScript file project04-02.js to copy:
// code for javascript to have the strict mode on
"use strict";
/* JavaScript 7th Edition
Chapter 4
Project 04-02
Application to display a random Jane Austen Quote
Author: John doe
Date: 17/2/2022
Filename: project04-02.js
*/
// Array of Jane Austen Quotes
let quotes = [
"It is a truth universally acknowledged, that a single man in possession of a good fortune, must be in want of a wife.",
"I hate to hear you talk about all women as if they were fine ladies instead of rational creatures. None of us want to be in calm waters all our lives.",
"Silly things do cease to be silly if they are done by sensible people in an impudent way.",
"Give a girl an education and introduce her properly into the world, and ten to one but she has the means of settling well, without further expense to anybody.",
"Life seems but a quick succession of busy nothings.",
"Our scars make us know that our past was for real.",
"I cannot speak well enough to be unintelligible.",
"One cannot be always laughing at a man without now and then stumbling on something witty.",
"Men were put into the world to teach women the law of compromise.",
"The person, be it gentlemen or lady, who has not pleasure in a good novel, must be intolerably stupid.",
];
// Run the quote generator every time the page loads
window.addEventListener("load", quoteGenerator);
// Function to generate and display a random quote
function quoteGenerator() {
// Number of quotes in the array
// Code Fix: declare the variable using "let" keyword
let quoteCount = quotes.length; // is 10
// Generate a random integer to select a quote
// Code Fix: declare the variable using "let"
// LOGICAL Error fix: Get value of random number from 0 to 9 instead of 0 to 10 because the array of "quotes" has 10 elements from index 0 to index 9
// Hence, use randomInt(0, quoteCount - 1) instead of randomInt(0, quoteCount)
let randomQuote = randomInt(0, quoteCount - 1);
// Retrieve a randomly-selected quote
// Code Fix: use "randomQuote" as the name of variable instead of "randomQuotes"
// Code Fix: declare the variable using "let" keyword
let quote = quotes[randomQuote];
// console.log(randomQuote);
// Display the random quote
// Code Fix: It's getElementsByTagName() method instead of getElementByTagName() to get the <blockquote> element
// Code Fix: Get first element by using [0] index instead of [1] since the 1st element of array is at index 0 in array
document.getElementsByTagName("blockquote")[0].innerHTML = quote;
}
/*=================================================================*/
// Function to return a randomly-selected integer between lowest and highest, inclusive
function randomInt(lowest, highest) {
let size = highest - lowest + 1;
return Math.floor(lowest + size * Math.random());
}
Text format of code for the HTML file or webpage project04-02.html to copy:
<!DOCTYPE html>
<html>
<head>
<!--
JavaScript 7th Edition
Chapter 4
Hands-on Project 4-2
Author: John doe
Date: 17/2/2022
Filename: project04-02.html
-->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title>Hands-on Project 4-2</title>
<link rel="stylesheet" href="styles.css" />
<!-- js file (named project04-02.js) reference -->
<script src="project04-02.js" defer></script>
</head>
<body>
<header>
<h1>Hands-on Project 4-2</h1>
</header>
<article>
<h2>Random Quotes from Jane Austen</h2>
<blockquote></blockquote>
</article>
</body>
</html>
Trending now
This is a popular solution!
Step by step
Solved in 6 steps with 5 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)