Table 3 Exercises

< CS101

For these exercises, we use and (&&), or (||) to combine multiple tests in an if-test. The baby fields are "name", "rank", "gender", "year".

1. Write code to print all the rows where the name starts with "X" or the name starts with "Y". Suggestion: when you have code running, look carefully at the output. Does the output look reasonable? For this problem for example, do you see a mix of names starting with either "X" or "Y"? It's nice if you can quickly check the correctness of your code right when you run it.


table-3-ex1

2. Write code to print all the rows where the name starts with "B" and the name ends with "a". As above, glance at the output to check that it looks right.


table-3-ex2

3. Write code to print all the rows where the name ends with "i" and the gender is "boy". Reminder of "boy" test: row.getField("gender") == "boy"


table-3-ex3

4. Write code to print all the rows where the rank is <= 10 and the gender is "boy" (i.e. the top 10 boy names).


table-3-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-3-ex1 table-3-ex2 table-3-ex3 table-3-ex4

(code appears here)