Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CS1301 Introduction To Computer Programming (07-08 Semester B) www.cs.cityu.edu.hk/~helena Lecture Exercise (Wk8) Q.1 [Use of while-loop] (a) Write.

Similar presentations


Presentation on theme: "1 CS1301 Introduction To Computer Programming (07-08 Semester B) www.cs.cityu.edu.hk/~helena Lecture Exercise (Wk8) Q.1 [Use of while-loop] (a) Write."— Presentation transcript:

1

2 1 CS1301 Introduction To Computer Programming (07-08 Semester B) www.cs.cityu.edu.hk/~helena Lecture Exercise (Wk8) Q.1 [Use of while-loop] (a) Write a function that returns a string which contains all 3’s multiples from 0 to 30 (each number should be followed by a line break): … function listNumbers() { } … (b) Modify the above function such that each number is indicated with an “(odd)” or “(even)” label:

3 2 CS1301 Introduction To Computer Programming (07-08 Semester B) www.cs.cityu.edu.hk/~helena Lecture Exercise (Wk8) Q.2 Write the code that asks the user to input 2 temperatures in Fahrenheit, say 95 and 105 (using the prompt dialog). Then display the table of temperature conversions within the range (using document.write). Temperature Conversions Temperature Conversion (Fahrenheit to Celsius)

4 3 CS1301 Introduction To Computer Programming (07-08 Semester B) www.cs.cityu.edu.hk/~helena Lecture Exercise (Wk8) Q.3 ROUND THE CLOCK The following shows a clock value (24 hours: 0,1,2,..23,0,1,2..). When the user clicks "Advance 1 hour", the clock is updated. Rewrite the code by using % CS1301 DEMO var c=0; //Global variable: the clock value //advance the clock function move() { c=c+1; if (c==24) c=0; document.getElementById('time').innerHTML=c; } 0 O'clock Advance 1 hour

5 4 CS1301 Introduction To Computer Programming (07-08 Semester B) www.cs.cityu.edu.hk/~helena Lecture Exercise (Wk8) Q.4 The Photo Gallery application : Change the code to add the "Change Page Size" button (number of images per page) and make it work: //Current left most image number in the page var currentStartImageNum=1; //Update the page: paragraph of images function makeHtmlOfImages() {var i; var htmlOfImages=''; i=currentStartImageNum; while (i<=currentStartImageNum+3) { htmlOfImages = htmlOfImages + ' '; i++; } document.getElementById('images').innerHTML=htmlOfImages; } //Show next page function goNext() { if (currentStartImageNum==17) { alert('This is the last page'); return; } currentStartImageNum=currentStartImageNum+4; makeHtmlOfImages(); } //Show previous page function goPrev() { if (currentStartImageNum==1) { alert('This is the first page'); return; } currentStartImageNum=currentStartImageNum-4; makeHtmlOfImages(); } … … - Classify the variables used above. Global variables: Local variables: - Can we change all the global variables to local? - Should we change all the local variables to global?


Download ppt "1 CS1301 Introduction To Computer Programming (07-08 Semester B) www.cs.cityu.edu.hk/~helena Lecture Exercise (Wk8) Q.1 [Use of while-loop] (a) Write."

Similar presentations


Ads by Google