{ "key_pair_value_system": true, "answer_rating_count": "", "question_feedback_html": { "html_star": "", "html_star_feedback": "" }, "answer_average_rating_value": "", "answer_date_js": "2024-09-04T15:25:51-04:00", "answer_date": "2024-09-04 15:25:51", "is_docs_available": null, "is_excel_available": null, "is_pdf_available": null, "count_file_available": 0, "main_page": "student_question_view", "question_id": "9114047", "url": "\/study-help\/questions\/41-from-1-to-12-4-how-to-work-with-9114047", "question_creation_date_js": "2024-09-04T15:25:51-04:00", "question_creation_date": "Sep 04, 2024 03:25 PM", "meta_title": "[Solved] 4.1 from 1 to 12 4 How to work with JavaS | SolutionInn", "meta_description": "Answer of - 4.1 from 1 to 12 4 How to work with JavaScript objects, functions, and even Chapte Exercise 4-1 In this exercise, you' | SolutionInn", "meta_keywords": "4.1,1,12,4,work,javascript,objects,functions,chapte,exercise,4-1,ll", "question_title_h1": "4.1 from 1 to 12 4 How to work with JavaScript objects, functions, and even Chapte Exercise 4-1 In this exercise, you'll Enhance the MPG", "question_title": "4.1 from 1 to 12 4 How to work with JavaScript objects,", "question_title_for_js_snippet": "4 1 from 1 to 12 4 How to work with JavaScript objects, functions, and even Chapte Exercise 4 1 In this exercise, you'll Enhance the MPG application Il enhance the validation for the MPG application, and v l provide for clearing the entries from the form Calculate Miles Per Gallon Mies Driven Gallons of Gas Used Mles Per Gallon Calculate MPG Clear Entries This page says Miles must be numeric and greater than zero oK l you have any problems when you're testing, remember to use Chrome's developer tools as shown in figure 1 16 of chapter 1 Test the application Open your text editor or IDE, and open this HTML file enjavascript jqueryexercises ch04 mpg index html Then, review the JavaScript code to see that it's the same as in figure 4 10 2 Tes this application with valid data to see how it works When you click the Calculate MPG button, the corret result should be displayed the data validation routine Note that one error message is displayed in an g box if either entry is nonnumeric or if either entry is less than or equal to zero Fabance the data validation e ke he es statement that provides the data validation so it checks each e dipl paralely, If the data in a text box is invalid, an error message should lext box and the focus should be moved to that text box Test this change to be sure bx if it contains invalid data wide error message is displayed for a text Aad s Clee Fing the entries from the form TML tries buto MPG button To do that, copy he istments for the Calculate button, and paste Cment for the Calculate button Then, modify the HTMI on so it has a unique id and an appropriate value Section1JavaScript essentials Add a function expression named clearEntries) that clears the entries in the four text boxes Then, add a statement in the onload event handler that attaches the clearEntries) function to the click event of the Clear Entries button 7 Add a statement to the onload event handler that attaches the clearEntrieso) function to the double click event of the miles text box Then, test this change 8 See what happens when you remove strict mode 9 Change the second statement in the calculateMpgO function as follows so the variable name is misspelled as Mpg instead of mpg var nog (miles gallons) Mpa mpg torixed(1) return mpg 10 Test this application with valid entries, and note that it doesn't work Then, press F12 to display the developer tools, click on the Console tab, and see this error message Mpg is not defined This shows that strict mode prevents the declaration of a variable without using the var keyword 11 Delete the strict mode declaration, and test again with the 1000 for miles and 33 for gallons This time, the application works, but the result isn't rounded That's because the JavaScript engine treated Mpg as a new variable 12 Restore the strict mode declaration and return the variable name to mpg Exercise 4 2 Build a new Future Value In this exercise, you will build a new version of the Future Value application of Then, test again to make sure the application is working application chapter 3 Its user interface will look like this Future Value Calculator Total Investment 10000 Annual Interest Rate 75 Number of Years 10 Future Value 206 10 32 Calculate If you have any problems when you're testing, remember to use Chrome's developer tools as shown in figure 1 16 of chapter 1 Open and review the starting files 1 Open your text editor or IDE, and open the HTML and JavaScript iles in this folder javascript iquerylexercisesich04 future value Chapter 4 How to work with JavaScript objects fiunctions, and events The Miles Per Gallon application in a browser Calculate Miles Per Gallon Miles Driven 2021 Gallons of Gas Used p63 Mies Per Gallon The HTML and JavaScript for the application chead calculate KPG c head cmain caleulate Miles Per Gallon Mles Per Gallon Figure 4 10 The Miles Per Gallon application", "question_description": "
4.1 <\/div>
<\/div>
from <\/div>
<\/div>
1 to 12 <\/div>
\"image <\/div>
\"image <\/div>
\"image <\/div> <\/div> 4 How to work with JavaScript objects, functions, and even Chapte Exercise 4-1 In this exercise, you'll Enhance the MPG application Il enhance the validation for the MPG application, and v l provide for clearing the entries from the form. Calculate Miles Per Gallon Mies Driven Gallons of Gas Used Mles Per Gallon Calculate MPG Clear Entries This page says Miles must be numeric and greater than zero oK l you have any problems when you're testing, remember to use Chrome's developer tools as shown in figure 1-16 of chapter 1. Test the application . Open your text editor or IDE, and open this HTML file: enjavascript-jqueryexercises \\ch04\\mpg\\index.html Then, review the JavaScript code to see that it's the same as in figure 4-10. 2. Tes this application with valid data to see how it works. When you click the Calculate MPG button, the corret result should be displayed. the data validation routine. Note that one error message is displayed in an g box if either entry is nonnumeric or if either entry is less than or equal to zero. Fabance the data validation e ke he es statement that provides the data validation so it checks each e dipl paralely, If the data in a text box is invalid, an error message should lext box and the focus should be moved to that text box. Test this change to be sure bx if it contains invalid data. wide error message is displayed for a text Aad s Clee Fing the entries from the form TML tries buto MPG button. To do that, copy he istments for the Calculate button, and paste Cment for the Calculate button. Then, modify the HTMI on so it has a unique id and an appropriate value Section1JavaScript essentials Add a function expression named clearEntries) that clears the entries in the four text boxes. Then, add a statement in the onload event handler that attaches the clearEntries) function to the click event of the Clear Entries button. 7. Add a statement to the onload event handler that attaches the clearEntrieso) function to the double-click event of the miles text box. Then, test this change 8. See what happens when you remove strict mode 9. Change the second statement in the calculateMpgO function as follows so the variable name is misspelled as Mpg instead of mpg. var nog -(miles \/ gallons) Mpa mpg.torixed(1) return mpg 10. Test this application with valid entries, and note that it doesn't work. Then, press F12 to display the developer tools, click on the Console tab, and see this error message: Mpg is not defined. This shows that strict mode prevents the declaration of a variable without using the var keyword. 11. Delete the strict mode declaration, and test again with the 1000 for miles and 33 for gallons. This time, the application works, but the result isn't rounded. That's because the JavaScript engine treated Mpg as a new variable. 12. Restore the strict mode declaration and return the variable name to mpg Exercise 4-2 Build a new Future Value In this exercise, you will build a new version of the Future Value application of Then, test again to make sure the application is working. application chapter 3. Its user interface will look like this: Future Value Calculator Total Investment 10000 Annual Interest Rate 75 Number of Years: 10 Future Value 206 10 32 Calculate If you have any problems when you're testing, remember to use Chrome's developer tools as shown in figure 1-16 of chapter 1. Open and review the starting files 1. Open your text editor or IDE, and open the HTML and JavaScript iles in this folder: javascript iquerylexercisesich04\\future_value Chapter 4 How to work with JavaScript objects. fiunctions, and events The Miles Per Gallon application in a browser Calculate Miles Per Gallon Miles Driven 2021 Gallons of Gas Used p63 Mies Per Gallon The HTML and JavaScript for the application chead> calculate KPG<\/title> <link rel- href-> <script strict vart function return document.getelementbyid : var calculateltpg gailona mpg mpgpg torixed processentries funetion miles parsefloat gallons='parserioat($(\"gallons\").value),' alert both entries must be numeric greater than zero calculatempg else if window.onload t> c\/head> <body> cmain> <h1>caleulate Miles Per Gallon<label tor \"miles>iies Driven: cinput type- \"text id\"miles\"> <labe1 Eor-\"gallona-sgailons of Gas Usedi <input type:\"text\", da-gallons .> <label for\".mpg.>Mles Per Gallon <input types\"text\" id- \"mpa\" disabled> <br <label>&nbep; Erper button idcaleulate values Caleulate MpG*> <bE> <\/script><\/body><p> Figure 4-10 The Miles Per Gallon application<\/p><\/html>", "transcribed_text": "", "related_book": { "title": null, "isbn": null, "edition": null, "authors": null, "cover_image": null, "uri": null, "see_more_uri": "" }, "free_related_book": { "isbn": "", "uri": "", "name": "", "edition": "" }, "question_posted": "2024-09-04 15:25:51", "see_more_questions_link": "\/study-help\/questions\/computer-science-operating-system-2022-August-09", "step_by_step_answer": "The Answer is in the image, click to view ...", "students_also_viewed": [ { "url": "\/study-help\/introduction-to-probability-statistics\/1311-university-textbooks-ii-refer-to-exercise-1310-a-use-1987563", "description": "13.11 University Textbooks II Refer to Exercise 13.10. a. Use the values of SSR and Total SS to calculate R. Compare this value with the value given in the printout. b. Calculate R(adj). When would...", "stars": 0 }, { "url": "\/wortham-publishing-completed-the-following-transactions-for-one-subscriber-during", "description": "Wortham Publishing completed the following transactions for one subscriber during 2014: Oct 1 Sold a one-year subscription, collecting cash of $1,800, plus sales tax of 9%. Nov 15 Remitted (paid) the...", "stars": 3 }, { "url": "\/study-help\/questions\/involves-being-honest-in-sharing-accurate-and-complete-information-about-10046495", "description": "______involves being honest in sharing accurate and complete information about the organization and workplace affairs. Information filtering Communication transparency Distributive negotiation...", "stars": 3 }, { "url": "\/study-help\/questions\/how-would-the-creation-of-an-import-quota-affect-the-2922869", "description": "How would the creation of an import quota affect the market for a good? Imported supply increases Domestic supply decreases Market price increases Consumer surplus increases Producer surplus decreases", "stars": 3 }, { "url": "\/study-help\/questions\/general-grapplegrommets-is-an-aerospace-parts-manufacturer-founded-in-1972-1000017", "description": "General Grapplegrommets is an aerospace parts manufacturer founded in 1972 in Wembley, Saskatchewan, that supplies landing gear components for a range of small passenger aircraft. Their head office...", "stars": 3 }, { "url": "\/study-help\/questions\/part-2-average-annual-salary-of-ohio-employees-6-suppose-1004532", "description": "Part 2: Average Annual Salary of Ohio Employees. 6. Suppose the average annual salary in dollars, A, of an Ohio employee is a function of the time of years since 2010, t. An approximate formula is A...", "stars": 3 }, { "url": "\/study-help\/questions\/question-1-a-large-domestic-airport-handles-90-takeoffs-per-1004697", "description": "Question 1: A large domestic airport handles 90 take-offs per hour. For take-off, an aircraft leaves the gate, taxies for some distance and awaits its turn on the runway. Average time spent by an...", "stars": 3 }, { "url": "\/study-help\/questions\/a-bond-has-a-yield-to-maturity-ym-1001427", "description": "A bond has a yield to maturity ( YM ) of 5 % , with a maturity of 3 0 years, the coupon payment is 2 5 dollars paid semi - annually. Given that the PAR of the bond is $ 1 , 0 0 0 what is the price of...", "stars": 3 }, { "url": "\/study-help\/questions\/question-3-d-your-friend-rochelle-has-launched-an-online-1004473", "description": "Question 3 d) Your friend Rochelle has launched an online store to sell framed photos of kittens to cat lovers all around the world. Rochelle is worried about some aspects of eCommerce - specifically...", "stars": 3 } ], "next_back_navigation": { "previous": "\/study-help\/questions\/question-1-25-marks-design-an-excel-financial-model-that-9114046", "next": "\/study-help\/questions\/on-june-30-2021-georgiaatlantic-inc-leased-a-warehouse-equipment-9114048" }, "breadcrumbs": [ { "name": "Study help", "link": "https:\/\/www.solutioninn.com\/study-help\/questions-and-answers" }, { "name": "Computer Science", "link": "https:\/\/www.solutioninn.com\/study-help\/questions-and-answers\/computer-science" }, { "name": "Databases", "link": "https:\/\/www.solutioninn.com\/study-help\/questions\/computer-science-databases" }, { "name": "4.1 from 1 to 12 4 How to work with JavaScript objects,", "link": "https:\/\/www.solutioninn.com\/study-help\/questions\/41-from-1-to-12-4-how-to-work-with-9114047" } ], "skill_details": { "skill_id": "656", "skill_name": "Databases", "parent_id": "8" } }