Discussion :  SOU CS Classes The fastest message board... ever.
Forum for discussion, questions, and replies relating to Web Development I 
Goto Thread: PreviousNext
Goto: Forum ListMessage ListNew TopicSearchLog In
Week 9 - Friday Discussion
Posted by: harveyd (IP Logged)
Date: November 20, 2007 07:28PM

1. Describe the syntax for one of the four types of loops.
i. for
ii. while
iii. do
iv. recursive
2. What prints (answer at most one of these)
i. var i=0, sum=0; for (i=0;i<10;i+=2) {sum+=i; alert(sum);} alert(sum);
ii. var i=0, sum=0; while (i<5) {sum += 3*i; i++; } alert(sum);
iii. var i=0, sum=0; do {sum += i-5; i++;} alert(sum);
3. What is wrong with the following loops and conditions
i. if i<5 alert("i is less than 5");
ii. if (i>=5) alert("i is greater than or equal to five");
iii. if (i==3) i++; alert("i was 3, now it's 4");
iv. var i=0; while (i<=5) alert(i); alert(loop executed 6 times);
4. Create a function that alerts("hello") ten times by one of the following approaches. Be careful, an infinite loop of alerts will make it impossible to exit the browser.
i. 'for' loop
ii. while {} loop
iii. do {} while () loop
iv. settimeout message
5. Use one of the loop types to sum the numbers from 1 to 100, and alert the result.
i. 'for' loop
ii. while {} loop
iii. do {} while () loop
iv. settimeout method
6. What is a good discussion topic for future classes?
7. What would be a good lab project?
8. Create a test question that you think would be good to add to either the on-line lecture, for a synthesis question, or for a quiz. Answer your question.
9. What do you wish you knew at the start of the lab project?
10. What suggestions do you have for the on-line lectures, lab projects, power point slides, etc.?
11. What mistakes did you find in the on-line material?

Re: Week 9 - Friday Discussion
Posted by: (IP Logged)
Date: November 27, 2007 03:36AM

4. Create a function that alerts("hello") ten times by one of the following approaches. Be careful, an infinite loop of alerts will make it impossible to exit the browser.

ii. while {} loop: var i=1, sum=0
while (i<10)
{ sum += i++; }
alert(sum);

iii. do {} while () loop: var i=0, sum=0;
do
{ sum += i++;
}while (i<=10);
alert(sum);

Re: Week 9 - Friday Discussion
Posted by: (IP Logged)
Date: November 27, 2007 03:16PM

5. Use one of the loop types to sum the numbers from 1 to 100, and alert the result.
var i=0, sum=0
do{ sum+= i++;
}while (i<=100);
alert(sum)

ii. var i=0, sum=0; while (i<5) {sum += 3*i; i++; } alert(sum);
0
3
9
18
30

Re: Week 9 - Friday Discussion
Posted by: (IP Logged)
Date: December 03, 2007 05:35AM

3. What is wrong with the following loops and conditions
i. if i<5 alert("i is less than 5");
if (i<5) alert( "i is less than 5");



Sorry, only registered users may post in this forum.
This forum powered by Phorum.