Go to the updateCount () function. Insert at the bottom of the function a try catch finally statement that does the following: a. Within the try statement, test if the charCount variable is greater than the value of the MAX REVIEW constant. If it is, throw an exception with the error message “You have exceeded the character count limit". b. For caught exceptions, display the error message within the innerHTML of the warningBox object. c. Whether the exception is thrown or not, change the innerHTML of the wordCountBox object to the value of the charCount variable. Save your changes to the file and then load project04-03.html in your web browser. Start typing text into the comment box. There are several errors within the code. Use the debugger to find any syntax or runtime errors you encounter. Fix the errors in your code editor. When the app is free of errors, attempt to type more than 100 characters into the comment box. Verify that when you exceed the character limit, a warning message appears on the page. Return to your code editor and increase the value of MAX_COUNT from 100 to 1000.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

A debugging question, thank you!!

4. Go to the updateCount () function. Insert at the bottom of the function a try catch finally statement
that does the following:
a. Within the try statement, test if the charCount variable is greater than the value of the MAX REVIEW
constant. If it is, throw an exception with the error message “You have exceeded the character count limit".
b. For caught exceptions, display the error message within the innerHTML of the warningBox object.
c. Whether the exception is thrown or not, change the innerHTML of the wordCountBox object to the value
of the charCount variable.
5. Save your changes to the file and then load project04-03.html in your web browser. Start typing text into the
comment box.
6. There are several errors within the code. Use the debugger to find any syntax or runtime errors you encounter.
Fix the errors in your code editor.
7. When the app is free of errors, attempt to type more than 100 characters into the comment box. Verify that
when you exceed the character limit, a warning message appears on the page.
8. Return to your code editor and increase the value of MAX COUNT from 100 to 1000.
Transcribed Image Text:4. Go to the updateCount () function. Insert at the bottom of the function a try catch finally statement that does the following: a. Within the try statement, test if the charCount variable is greater than the value of the MAX REVIEW constant. If it is, throw an exception with the error message “You have exceeded the character count limit". b. For caught exceptions, display the error message within the innerHTML of the warningBox object. c. Whether the exception is thrown or not, change the innerHTML of the wordCountBox object to the value of the charCount variable. 5. Save your changes to the file and then load project04-03.html in your web browser. Start typing text into the comment box. 6. There are several errors within the code. Use the debugger to find any syntax or runtime errors you encounter. Fix the errors in your code editor. 7. When the app is free of errors, attempt to type more than 100 characters into the comment box. Verify that when you exceed the character limit, a warning message appears on the page. 8. Return to your code editor and increase the value of MAX COUNT from 100 to 1000.
1
"use strict";
JavaScript 7th Edition
Chapter 4
Project 04-03
2
/*
Application to count the number of characters in a review comment
7
Author:
8.
Date:
10
Filename: project04-03.js
11
*/
12
13
// Maximum Length of Review
14
const MAX_REVIEW = 100;
15
document.getElementById("limit").innerHTML = MAX_REVIEW;
16
// Reference to elemets in the web page
let wordCountBox = document.getElementById ("countValue");
let warningBox = document.getElementById("warningBox");
17
18
19
20
21
// Event listener for typing into the comment box
document.getElementById("comment").addEventListener(keyup, updateCount);
22
23
24
// Function to update the count with each keyup event
function updateCount() {
// Set the warning box to an empty text string
warningBox.innerHTML = "";
25
26
27
28
29
30
// Count the number of characters in the comment box
31
commentText = document.getElementById("comment").value;
32
charCount = countCharacters(commentText);
33
34
try {
35
if (!(charCount.value > MAX_REVIEW))
36
throw "You have exceeded the character count limit";
37
} catch (error) {
38
warningBox.innerHTML = error;
}
39
40
finally {
41
wordCountBox.innerHTML = charCount;
42
}
43
44
}
45
46
47
48
49
50
// Function to count the number of characters in a text string
51
function countCharacters (textStr) {
52
var commentregx = /\s/g;
var chars = textStr.replace (commentregx, "");
return chars.length;
53
54
55
}
Transcribed Image Text:1 "use strict"; JavaScript 7th Edition Chapter 4 Project 04-03 2 /* Application to count the number of characters in a review comment 7 Author: 8. Date: 10 Filename: project04-03.js 11 */ 12 13 // Maximum Length of Review 14 const MAX_REVIEW = 100; 15 document.getElementById("limit").innerHTML = MAX_REVIEW; 16 // Reference to elemets in the web page let wordCountBox = document.getElementById ("countValue"); let warningBox = document.getElementById("warningBox"); 17 18 19 20 21 // Event listener for typing into the comment box document.getElementById("comment").addEventListener(keyup, updateCount); 22 23 24 // Function to update the count with each keyup event function updateCount() { // Set the warning box to an empty text string warningBox.innerHTML = ""; 25 26 27 28 29 30 // Count the number of characters in the comment box 31 commentText = document.getElementById("comment").value; 32 charCount = countCharacters(commentText); 33 34 try { 35 if (!(charCount.value > MAX_REVIEW)) 36 throw "You have exceeded the character count limit"; 37 } catch (error) { 38 warningBox.innerHTML = error; } 39 40 finally { 41 wordCountBox.innerHTML = charCount; 42 } 43 44 } 45 46 47 48 49 50 // Function to count the number of characters in a text string 51 function countCharacters (textStr) { 52 var commentregx = /\s/g; var chars = textStr.replace (commentregx, ""); return chars.length; 53 54 55 }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY