Table 4 Exercises

< CS101

For these exercises, write code to count names which meet certain conditions and print a line like the following to report the count.

count: 23

The code to produce the above line looks like following, but the real work is in initializing and updating the count variable (or whatever variable you use).

print("count:", count);

The starter code includes the standard count = 0; line to set count to zero before starting.

1. Write code to count and print number of names starting with the letter "O". The last line printed should look like the "count: 23" example above (note: the answer is not 23, that's just a number I made up).


table-5-ex1

2. Write code to count and print number of girl names starting with "T". The last line printed should look like the "count: 23" example above.


table-5-ex2

3. Write code to count and print number of boy names ending with "d". The last line printed should look like the "count: 23" example above.


table-5-ex3

4. How many names ending in "m" are there with a rank <= 500? Write code to count and print this number. As usual, the last line printed should look like the "count: 23" example above.


table-5-ex4


Each click of a Run button saves that code to disk on the computer running the browser. The button below retrieves the code exercises listed to the right of the button.

count 4 : table-5-ex1 table-5-ex2 table-5-ex3 table-5-ex4

(code appears here)