Question: In this week s Critical Thinking Assignment, you ll continue working with the tuba.js and tractor.htm files from the chapter. You ll add error handling
In this weeks Critical Thinking Assignment, youll continue working with the tuba.js and tractor.htm files from the chapter. Youll add error handling to the verifyCrops function so users receive an error message if they remove checkmarks from all the crop boxes.
Use the file manager for your operating system to copy all the files and subfolders from the Chapter Download ChapterChapter directory in your Data Files, and paste them in the Chapter HandsOnProject folder. Verify that you still have a copy in the ChapterChapter directory.
In your text editor, open tuba.js from the ChapterHandsOnProject folder, and then in the comment section, replace the text Chapter case with Handson Project
Scroll down to the verifyCrops function, and then delete the line testFormCompleteness; so the command block is empty.
Enter the following try statement within the command block of the verifyCrops function:
try
for var I ; i ; i
if cropsFieldsetgetElementsByTagName inputichecked
cropscomplete true;
messageElement.innerHTML ; clear previous message or recommendation
testFormCompleteness ;
i ;
if i
throw "Please select at least one crop.";
Note that the code shown in Steps and is not free of bugs. You will debug the code later in the next project.
Below the try statement but before the closing of the verifyCropsfunction add the following catch statement:
catch message
cropsComplete false;
messageHeadEleemnt.innerHTML ; remove any former recommendation heading
messageElement.innerHTML message; display error message
Scroll to the top of the document, and then change the values for the variables acresComplete, cropsComplete, and monthsComplete to false. Note that the value for the fuelComplete variable should remain true.
Save your changes to js and open tractor.htm in a browser, and then test the crops boxes by selecting some and then unselecting all of them. Notice that an error message is displayed when no crops boxes are checked, as shown in Figure and the message is removed when any crops box is checked.Figure : Error message displayed; Screen capture that shows a green background with a farm tractor in the left hand navigation bar;
Close the tractor.htm file in your browser.
Submission Requirements:
Your papersubmission should meet the following requirements:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
