Click to reopen instructions.

This assessment consists of functions you need to write involving primarily string expressions. It is a closed book assessment. You should stay on this tab until you are done and there should be no talking. This assessment is about how much you understand. There are no automatic tests but you can use the REPL to test things yourself. For example, after defining the firstHalf function and pressing the blue arrow, you can type firstHalf('foobar') in the repl and hit return to see if it evaluates to the expected 'foo'.

You can move through the questions with the arrows at the upper right next to the 1 of indicator so if you're not sure how to write one function move on to another one and come back if you have time at the end. I want to see how much you do know. Note: you can also click on thingsLikeThis in these instructions and the questions to copy them to the clipboard to avoid spelling mistakes. (I.e. click to copy and then ⌘-v to paste wherever you want.)

Some of these functions will be much easier (even trivial) to write if you use the indexOf method I introduced on the latest string functions assignment. To refresh your memory, indexOf takes a single argument, which should be a string, and returns the index at which the sting argument first occurres in the string on which the method is called. It returns -1 if the argument string is not found. For instance if s is our old standby "foobar" then s.indexOf("bar") is 3.

When you are done, please click on your Github username above and submit a GitHub pull request of the branch and request me as a reviewer. Doing this correctly is part of the assessment. If you are unsure how to request a review, please ask for help!

Put definitions here.

Revisions:

Questions of

Write a function named firstHalf that takes a single string argument and returns the first half of the string. (If the string has an odd number of characters it doesn't matter whether or not you include the extra character.) For instance the first half of 'foobar' is 'foo' but if the argument was 'fooquux' then either 'foo' or 'fooq' would be acceptable return values.

Write a function named secondHalf that takes a single string argument and returns the second half of the string. (If the string has an odd number of characters it doesn't matter whether or not you include the extra character.) For instance the second half of 'foobar' is 'bar' but if the argument was 'fooquux' then either 'quux' or 'uux' would be acceptable return values. For maximum style points write this function and firstHalf so that firstHalf(s) + secondHalf(s) gives you back s.

Write a function named upDown that takes a single string argument and returns a string consisting of the original string all in upper case concatenated (“smooshed together”) with the string all in lower case. E.g. called with 'foo' it should return 'FOOfoo'.

Write a function named firstFewEveryOther that takes a single string argument that is at least five characters long and returns a string consisting of just the first, third, and fifth characters of the argument string. E.g. called with 'foobar' it should return 'foa'.

Write a function named upDownLastCharacter that takes a single string argument that is at least one character long and returns a string consisting of two characters, the uppercase version of the last character of the argument string and the lowercase version of that same character. E.g. called with 'foo' it should return 'Oo'.

Write a function named firstAndLast that takes a single string argument (which will be at least two characters long) and returns a string consisting of just the first and last characters of the string.

Write a function named swapFrontAndBack that takes a single string argument and returns a string consisting of the second half of the original string followed by the first half. If the string is an odd number of characters it doesn’t matter whether the extra character goes with the front or the back.

As you should recall from the Pig Latin assignment, the rules of simple Pig Latin say that a word is translated into Pig Latin by taking everything up to (but not including) the first vowel and moving it to the end of word and then adding “ay” to the end.

Write a function named simplePigLatin that takes two arguments, a string containing a single word and a number indicating the index of the first vowel in the word, and returns the word translated into Pig Latin.

Write a function named randomCharacter that takes a single string argument and returns a random character from the string. For this function you will need to use the rand function defined at the top of the starter code.

Write a function named randomCharacterUpDown that takes a single string argument and returns a string consisting of a single random character repeated twice, once in upper case and then in lower case. For this function you will need to use the rand function defined at the top of the starter code.

Write a function named isAllUpperCase that takes a single string argument and returns a boolean indicating whether the string is all upper case.

Write a function named sameIgnoringCase that takes two string arguments and returns a boolean indicating whether they are the same string if you ignore case differences.

Write a function named firstName that takes a single string argument which will consist of a full name in the form first name, a space, and the last name and returns a string containing just the first name. You will probably want to use the indexOf method.

Write a function named lastName that takes a single string argument which will consist of a full name in the form first name, a space, and the last name and returns a string containing just the last name. You will probably want to use the indexOf method.

Write a function named initials that takes a single string argument which will consist of a full name in the form first name, a space, and the last name and returns a string containing the person's initials, i.e. the first letter of their first name followed by the first letter of their last name. You will probably want to use the indexOf method.

REPL