Class by class Assignments for Chapter 3: JavaScript Assignment 0 – Chapter 3 Introduction to JavaScript The javascript programs for this assignment are in Basic_JavaScript_Programs_Part_A Read Chapters 1-3 of JavaScript text In Chapter 1 you may ignore the material about specifying javascript versions In Chapter 2, don’t worry about learning the specific functions for dates, and the document functions; these will become automatic as you use them, and the date examples are simply that - examples. The only exception is that you should pay attention to the functions for generating output: the document.write( ) function, which display text on the page, the alert( ) function, which puts up an alert box, and the confirm( ) function, which requires a yes-or-no answer to a pop=up box. Examine the code for doc_write.html and doc_write_revisited.html Do Modify doc_write.html so that it prints out a short poem. Examine the miniTable.html page and modify it to add a third row of numbers. Read In Chapter 3 Pay attention to the alert(“my message” ) function. There is also a confirm( “my message”) function, which pops up a dialog box and allows only a yes or no answer. There is a prompt(“my prompt”) function which is the way you get input from a user. (next lesson). These are reviewed at the start of Chapter 4. Don’t worry too much about the event handlers; we will talk about them in more detail later in the course. The use of the ‘with’ statement is considered poor practice. Don’t do it! Do Modify your poem page so that you ask the reader if s/he liked it. (Use a confirm | box.) Read JSNotes 1 This will lead you to Where the JavaScript goes (in this folder) , which you should read. Read Chapter 4 of the JavaScript text. Most of this is review. Don’t worry about the location, history , etc. functions – you can look them up when you need them. You should simply know that they exist. Assignment 1 – Chapter 3 – Variables and Basic Functions The javascript programs for this assignment are in Basic_JavaScript_Programs_Part_A Read Chapter 5 of JS text and the review the Chapter 3 of the JavaScript text (on defining and calling functions; returning values from functions.) JSNotes 2 JSNotes 2A - Functions in JavaScript – Sections 1 and 2a. (We will come back to the rest later.) We will talk about strings more extensively when we talk about arrays (soon.) For now, just remember that lower and upper case letters are different characters. Do Examine function1.html code. Modify it so that the hello( ) function asks for your name and says hello using it. Hint: You will need to use a variable to hold the response from the alert: theUser=alert(“What is your name?”; Examine the version of function1 which uses and external file for the javascript, and also look at the file holding the script. Modify the script so that script asks for the user’s name and also the user’s age. Examine the code for functions2a1, functions2a2 and functions2a3. Modify the script you were working on immediately above so that the user’s age is converted to a number and your greeting tells the user how old s/he is and will be in 10 years. Examine the arith_functions programs. They should be clear. In class we will spend some time on global and local variables. We will work through the pages on type conversion and global change (items 5 and 6 on the index.) Read: Notes on JS from the Stefanov book. This is a short note about good programming style. Assignment 2 – Chapter 3 – Strings, Arrays, Sorting and Comparing; Control Statements The javascript programs for this assignment are in Basic_JavaScript_Programs_Part_B Read: Chapter 6 of the JavaScript text. Loops, if-else, etc. are exactly the same in JavaScript as they are in Python and Java, so you may depend on what you learned in CS 112-113 here. JSNotes 3. The material here is important and you should be sure you understand it. If not, you will need to puzzle it out in class. Do: Review your knowledge of if statements by examining the code for increments.html and increments2.html Examine the iffy1.html page and do the first problem in Exercise on If and Rounding. Bring to class any problems you have with this material. Examine the rounding.html page and do the second problem in Exercise on If and Rounding. Review your knowledge of arrays by reviewing the code in array1.html and arrays2.html Review your knowledge of for loops by examining the code in moreSimpleLoops.html and nestedLoops.html Look at the code in simpleLoops.html and write one or two sentences which explain how the twoTo( ) function works. In the page “Exercise on Loops” do the first problems You will do the second and third problems in class/lab. Review your knowledge of do and while loops by examining the code in doWhile.html Bring any questions to class. In class we will work our way through the deep copy issues. Assignment 3 – Chapter 3 – Functions, Objects and Associative Arrays The javascript programs for this assignment are in Basic_JavaScript_Programs_Part_B Read: JSNotes4 (which is a review of the previous work) Re-read JSNotes 2A (you may go lightly over section 6 on closures; it’s pretty hairy.) JSNotes5_v3 Chapter 7 in the text Review Chapter 4 in the text (browse) on what functions are built into the Math and Date and Time objects. I don’t expect you to memorize these, but merely to know they exist so that you can look up details as needed. Do: Examine the code for CustomObjects1.html, CustomObjects2.html and CustomObjects3.html Do the Exercise on Custom Objects Write a short paragraph which explains how an associative array is used to realize an object. In your paragaph you should explain what happens when you add a method or property to an object. What are you doing when you change the sort( ) method of an array? Read: Part 1 of Combined JavaScriptAccording to Douglas Crockford with Further Explanations in Unit 5 – Chapter 9. This is a sophisticated look at the data structures in JavaScript. Part 2 of Combined JavaScriptAccording to Douglas Crockford with Further Explanations in Unit 5 – Chapter 9 through section 6a. This is very sophisticated material and you will need to read it more than once. We will also be coming back to this material in Chapter 9. Do: Email me list of any specific things which you do not understand by 6 p.m. the day before class. Do the exercises in the Part 2 notes you have read.