Computer science

Beginning JavaScript Textbook Questions And Answers

US$14.99 US$24.00

b Chapter: 9- DOM Scripting -Problem: 2 /b Modify ch9_example6.html from the “Animating Content” Try It Out so that the amount of pixels moved in either direction is controlled by a global variable. Call it direction. Remove the switchDirection variable, and change the

Description

Chapter: 9- DOM Scripting -Problem: 2 >> Modify ch9_example6.html from the “Animating Content” Try It Out so that the amount of pixels moved in either direction is controlled by a global variable. Call it direction. Remove the switchDirection variable, and change the code to use the new direction variable to determine when the animation should change directions.
Answer Preview: Chapter } #divAdvert { 9, Question 2 position: absolute; font: 12px Arial; top: 4px; left: 0px; Here …

, Chapter: 4- Functions and Scope -Problem: 2 >> Modify the code of Question 1 to request the times table to be displayed from the user; the code should continue to request and display times tables until the user enters -1. Additionally, do a check to make sure that the user is entering a valid number; if the number is not valid, ask the user to re-enter it. Data from Question 1Change the code of Question 2 from Chapter 3 so that it’s a function
Answer Preview: The function remains the same, so lets look at the new code. The first change from Question 1 is tha…

, Chapter: 14- Ajax -Problem: 1 >> Extend the HttpRequest module to include synchronous requests in addition to the asynchronous requests the module already makes. You’ll have to make some adjustments to your code to incorporate this functionality.
Answer Preview: function HttpRequest (url, callback) { this url= url; this callBack = callback; this async = true; this request = new XMLHttpRequest(); }; HttpRequest prototype send = function () { this request open(…

, Chapter: 10- Events -Problem: 1 >> Add a method to the event utility object called isOldIE() that returns a boolean value indicating whether or not the browser is old-IE.
Answer Preview: var evt = { add Listener: function(obj, type, fn) { if (typeof obj addEventListener != "…

, Chapter: 7- Date, Time, and Timers -Problem: 1 >> Create a page that gets the user’s date of birth. Then, using that information, tell her on what day of the week she was born.
Answer Preview: The solution is rather simple. You create a new Date object based on the y…

, Chapter: 11- HTML Forms: Interacting with the User -Problem: 2 >> Create a user interface that allows users to pick the computer system of their dreams, similar in principle to the e-commerce sites selling computers over the Internet. For example, they could be given a choice of processor type, speed, memory, and hard drive size, and the option to add additional components like a DVD-ROM drive, a sound card, and so on. As the users change their selections, the p
Answer Preview: Chapter 11: Question 2 Choose the components you want included on your computer Processor Dual-core 2GHz Quad-core 2 4GHz Eight-core 3GHz Solid-state Drive 250GB 512GB 1TB DVD-ROM > Blu-ray Case Deskt…

, Chapter: 3- Decisions and Loops -Problem: 2 >> Using document.write(), write code that displays the results of the 12 times table. Its output should be the results of the calculations. Transcribed Image Text: * 12 1 = 12 * 12 2 = 24 12 * 3 = 36... 11 = 132 12 = 144 * 12 12 *
Answer Preview: Chapter 3: Question 2 var timesTable = 12; for (var timesBy = 1; times …

, Chapter: 14- Ajax -Problem: 2 >> It was mentioned earlier in the chapter that you could modify the smart form to not use hyperlinks. Change the form that uses the HttpRequest module so that the Username and Email fields are checked when the user submits the form. Listen for the form’s submit event and cancel the submission if a username or e-mail is taken.
Answer Preview: First, a disclaimer: Ideally, the service provided by ch14_formvalidator php should allow you to check both the username and e-mail address with a single request. That would greatly simplify this solu…

, Chapter: 17- Other JavaScript Libraries -Problem: 2 >> If you guessed that this question would be: “Change the answer to Chapter 14’s Question 2 using MooTools, and add error reporting for when an error occurs with the Ajax request” then you won!! Your prize is… completing the exercise.
Answer Preview: Chapter .fieldname { } } 17: Question 2 .submit { text-align: right; text-align: right; Username: Em…

, Chapter: 9- DOM Scripting -Problem: 1 >> Here’s some HTML code that creates a table. Re-create this table using only JavaScript and the core DOM objects to generate the HTML. Test your code in all browsers available to you to make sure it works in them. Hint: Comment each line as you write it to keep track of where you are in the tree structure, and create a new variable for every element on the page (for example, not just one for each o
Answer Preview: It seems a rather daunting example, but rather than being difficult, it is just a conjunction of two areas, one building a tree structure and the other navigating the tree structure. You start at the …

, Chapter: 6- String Manipulation -Problem: 3 >> Imagine you have a website with a message board. Write a regular expression that would remove barred words.
Answer Preview: For this example, pretend youre creating script for a board on a dieting site where text relating to …

, Chapter: 13- Data Storage -Problem: 2 >> Use local storage to load a different advertisement every time a user visits a web page.
Answer Preview: Chapter 13: Question 2 you!" var ads = [ "Buy Product A! You won't be sorry!", "You need Product B! Buy buy buy!", "Don't buy Product A or B! Product …

, Chapter: 11- HTML Forms: Interacting with the User -Problem: 1 >> Using the code from the temperature converter example you saw in Chapter 2, create a user interface for it and connect it to the existing code so that the user can enter a value in degrees Fahrenheit and convert it to centigrade.
Answer Preview: Chapter 11: Question 1 function convertToCentigrade (degFahren) { var degCent= 5/9 * (degFahren - 32…

, Chapter: 6- String Manipulation -Problem: 2 >> Write a regular expression that finds all of the occurrences of the word “a” in the following sentence and replaces them with “the”: “a dog walked in off a street and ordered a finest beer” The sentence should become: “the dog walked in off the street and ordered the finest beer”
Answer Preview: With regular expressions, its often not just what you want to match, but also what you dont wan…

, Chapter: 3- Decisions and Loops -Problem: 1 >> A junior programmer comes to you with some code that appears not to work. Can you spot where he went wrong? Give him a hand and correct the mistakes.var userAge = prompt("Please enter your age"); Transcribed Image Text: if (userAge = 0) {; alert ("So you're a baby!"); } else if (userAge < 0 | userAg
Answer Preview: Oh dear, our junior programmer is having a bad day! There are two mistake…

, Chapter: 5- JavaScript—An Object-Based Language -Problem: 1 >> Using the Date type, calculate the date 12 months from now and write this into a web page.
Answer Preview: Chapter 5: Question 1 var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep…

, Chapter: 6- String Manipulation -Problem: 1 >> What problem does the following code solve?Why would this not work, and how could you rectify the problem? Transcribed Image Text: var myString = "This sentence has has a fault and and we need to fix it." var myRegExp = /(bw+b) 1/g; myString = myString.replace(myRegExp, "$1"); Now imagine that y
Answer Preview: The problem is that the sentence has has has and and and inside it, clearly a mistake. A lot of word …

, Chapter: 8- Programming the Browser -Problem: 1 >> Create two pages, one called legacy.html and the other called modern.html. Each page should have a heading telling you what page is loaded. For example:Using feature detection and the location object, send browsers that do not support geolocation to legacy.html; send browsers that do support geolocation to modern.html. Tra
Answer Preview: The modern html page is as follows: Chapter 2: Question 1 Welcome to the Modern page! if (!navigat…

, Chapter: 4- Functions and Scope -Problem: 1 >> Change the code of Question 2 from Chapter 3 so that it’s a function that takes as parameters the times table required and the values at which it should start and end. For example, you might try the 4 times table displayed starting with 4 * 4 and ending at 4 * 9. Data from Question 2 from Chapter 3Using document.write(), write code that displays the results of the 12 times table. Its output should
Answer Preview: Youve declared your function, calling it writeTimesTable(), and given it three parameters. The first …

, Chapter: 2- Data Types and Variables -Problem: 2 >> The following code uses the prompt() function to get two numbers from the user. It then adds those two numbers and writes the result to the page:However, if you try out the code, you’ll discover that it doesn’t work. Why not? Change the code so that it does work. Transcribed Image Text: Chapter 2
Answer Preview: The data that the prompt() actually obtains is a string. So both firstNumber and secondNumber contai…

, Chapter: 13- Data Storage -Problem: 1 >> Using local storage, create a page that keeps track of how many times the page has been visited by the user in the last month.
Answer Preview: Chapter 13: Question 1 var pageViewCount = localStorage getItem("pageViewCount"); var pageFirstVisited = localStorage getItem("pageFirstVisited"); var …

, Chapter: 18- Common Mistakes, Debugging, and Error Handling -Problem: 1 >> The example ch18_example4.html has a deliberate bug. For each times table it creates only multipliers with values from 1 to 11.Use the script debugger to work out why this is happening, and then correct the bug.
Answer Preview: The problem is with the codes logic rather than its syntax…

, Chapter: 5- JavaScript—An Object-Based Language -Problem: 2 >> Obtain a list of names from the user, storing each name entered in an array. Keep getting another name until the user enters nothing. Sort the names in ascending order and then write them out to the page, with each name on its own line.
Answer Preview: Chapter 5: Question 2 var inputName = ""; var namesArray = []; while ((inputName = prompt("Enter a n…

Additional Information

Book:
Beginning JavaScript
Isbn:
ISBN: 9781118903339
Edition:
5th Edition
Author:
Authors: Jeremy McPeak
Image:
64c9dfc260fe8_37490.jpg

5 Reviews for Beginning JavaScript Textbook Questions And Answers

Aryana Forbes
Nice job.
Elijah Pratt
Thank you!
Joaquin Monroe
thank you
Sage Barton
Dax Howe

Add a review

Your Rating

84209

Character Limit 400