Class 9 — Class exam 2 — Regular expression examples

Class exam

All questions are on Javascript.

The class exam will be about 75 minutes at the start of the class.

Then we will have a break and continue with Regular expression topics.

Exam questions

Look at and become familiar with the exam instructions. exam instructions for class exams and the final examination.

Exam questions can be based on the following sources: (1) on-line web sites, (3) classes, (4) reports, (5) exercises, and (6) course web pages. They are based on topics from the beginning of the year up to and including the class before the exam, although more recent topics will be emphasized in later exams.

Consider all concepts and terminology used in on-line web sites, reports, and classes and ask the typical questions - how, why, when, where and what -- individually and in combination. In particular, variations are based on "describe", "explain", "define", "what is meant by", etc. you may be asked to do variations of some of the programming exercises.

Javascript programming questions

All these and similar questions an be answered by thinking about the items in the Javascript topics page and the example programs discussed in class.
  1. Given a script determine what it does.
  2. Given a partial script fill in the blanks to accomplish the specified task.
  3. Given one or more functions describe what they do. For example, what would be written to a web page?
  4. Given an function written with if..else statements, write a corresponding program with a switch statement, and vice-versa.
  5. Given a function written with one of the looping structures, write the algorithm using one of the other looping structures.
  6. Describe the two types of choice-control structure in Javascript. When do you choose one type over the other; i.e. what are their respective advantages and disadvantages.
  7. Describe the four types of loop-control structures in Javascript. When do you choose one type of loop structure over the others; i.e. what are their respective advantages and disadvantages.
  8. Describe the how to handle errors with the try-catch-throw statements.
  9. Describe the three types of control structure used in programming in any language.
  10. Describe the sources of errors in a program.
  11. Describe the types of error provided by Javascript.
  12. Write short functions that have parameters and return a result.
  13. What is an object literal and how is it used?

Examples of functions that you could be asked to write

All of these and other functions can be written with the concepts shown on the Javascript topics page and the example programs we have discussed in class.
  1. Return the maximum of three numbers, or the maximum of the three numbers could be written to the web page. For example:
              var max =  max_of_three(2, 30, -5)
              // The value of max would be 30)
  2. Reverse the items in an array or list. For example:
              var a1 = [1, 2, 3, 4, 5];
              var a2 = reverse(a1):
              // The value of a2 would be [5, 4, 3, 2, 1]. And
              var a3 = reverse(a2);  // has the value [1, 2, 3, 4, 5]
  3. Find the maximum numberin a list of numbers.
  4. Find the length of each string a list of strings.
  5. Find the sum of the numbers in a list, where the list could contain both numbers and non-numbers. For example in the list [1, “a”, “b, 2, true, 3] the sum of the numbers is 6.
  6. Given a list of arbitrary items. Count the number of stings or numbers or Booleans the list contains. There are many criteria that could be used for counting: how many are negative numbers; how many numbers are bigger than 100; how many strings contain the letter ‘A’ and are of length less than 5.
  7. Given two lists of numbers, do the lists have the same numbers in the same order?
              // r1 is true.
              var r1 = same_numbers( [1, 2, 3, 4, 5], [1, 2, 3, 4, 5])
              // r2 is false.
              var r2 = same_numbers([1, 2 ,3, 4, 5], [1, 2, 3, 5, 4])
            

Regular expressions

Try the regular expression practice program.