Emerging Scholars Program - Week 11

## Challenge From Last Time:

Somehow you find yourself in a room with 2 identical doors. One will lead you into an endless maze that will surely result in your death, the other will take you to freedom and happiness. You must choose one of the doors eventually because if you stay in the room, you will starve to death. In the room there are 2 identical talking birds, one always lies the other always tells the truth. You may ask only one of the birds only one simple question. This cannot be a complex sentence with lots of conjunctions. Will you ever get out of the room? If so, what question should you ask? If not, then why?

## Functions Я us

Answer the last challenge question or tell me something you know about strings in JavaScirpt to get a sandwich.

JavaScript is often used for form validation. That is, it's used to make sure that the input given by a user in the form is syntactically correct. Today we're going to write a couple of functions that could be used for form validation. Split up into groups of 3 and write the following functions. What do you think each of these functions could be used for?

1. Write a function that takes in a string and outputs the content of that string with all spaces, dashes, parenthesis, and periods removed.
```            function cleanUp(str)
{
...
return cleanStr;
}
```
2. Write a function that takes in a string and outputs the contents of the string with all leading and trailing spaces removed.
```            function trim(str)
{
...
return trimmedStr;
}
```
3. Write a function that takes in a string and outputs whether or not the string has one occurrence of an '@' (at sign) and at least one '.' (period), such that a period exists in the string sometime after the '@' sign.
```            function isValid(str)
{
...
return true;
...
return false;
}
```
Write your functions on a piece of paper in a legible way and find a group to swap papers with. Look at their answers and 1) check if they work and 2) if you think their's is more efficient than yours.

## A Challenge For Next Time:

A group of people live on an island. They are all perfect logicians. No one knows the color of their eyes. Every night at midnight, a ferry stops at the island. If anyone has figured out the color of their own eyes, they [must] leave the island that midnight. On this island live 100 blue-eyed people, 100 brown-eyed people, and the Guru. The Guru has green eyes, and does not know her own eye color either. Everyone on the island knows the rules (but are not given the total numbers) and is constantly aware of everyone else's eye color. Everyone keeps a constant count of the total number they see of each (excluding themselves). However, they cannot otherwise communicate. So any given blue-eyed person can see 100 people with brown eyes and 99 people with blue eyes, but that does not tell them their own eye color; it could be 101 brown and 99 blue. Or 100 brown, 99 blue, and the one could have red eyes.

The Guru speaks only once (let's say at noon), on one day in all their endless years on the island. Standing before the islanders, she says the following:

"I can see someone with blue eyes."

Who leaves the island, and on what night?