experiment with strings, numbers, variables,
+ operator, and calling functions.
If your code isn't working as expected, try opening up Firefox's error console to check for (potentially) helpful error messages. If you get stuck, don't hesitate to ask the instructor or a teaching assistant for help.
Tip: Here are some handy keyboard shortcuts:
Select-All: Command-A (Mac), Control-A (Windows)
Copy: Command-C (Mac), Control-C (Windows)
Paste: Command-V (Mac), Control-V (Windows)
alertstatement in the function by removing the
//symbols at the beginning of the line. (There will still be a comment to the right of the statement, at the end of the line.) What do you think the function will do now? Save the file and preview or reload the page, then click on the "Run Experiment" button to test your understanding. Update the comment at the end of the line to show what the output was.
In the first two statements, you displayed a string and a number.
The next five statements will
let you experiment with what the
+ operator does inside
and outside strings, and when given two numbers, two strings, or a number
and a string.
For each of these statements, indicate what you think the output will be in the comment at the end of the line. Then uncomment the statements, either one-by-one or all at once, save and re-preview/reload the file, and click "Run Experiment", comparing the actual output values with the values you expected. For each value that is different from what you expected, look at it again and see if you can see why the output was the way it was. If not, ask a neighbor, instructor, or TA to explain it to you. Update the end-of-line comments if necessary, to reflect the actual output.
alertfunction is a "Do Something" method (it does something for us), the
promptfunction is a "Return Something" method (it returns a value to us). That value is being stored in a variable, and is then being used in the next call to
Mary, she should see an alert window that contains a message such as
Hello Mary, I am glad to see you!.
Tip: Don't forget that the "+" symbol can be used to combine two or more strings.
mad Libfunction to construct a simple Mad Libs story. You should prompt for three words: one noun, one verb, and one adjective. Each word should be stored in an appropriately named variable. Then use an alert box to display a short story constructed using the words the user entered. A sample session might look like the following:
[prompt] Please enter a noun. [user enters] monkey [prompt] Please enter a verb. [user enters] jump [prompt] Please enter an adjective. [user enters] happy [alert] When I was walking to work today I saw a monkey! It was very happy and it made me want to jump. OR [alert] It's your turn to jump over the happy monkey.Be creative! If you wish, you may prompt for additional words and create a more involved story.
If you worked in a team, each member of your group should do this, so each of you has a link to the new mini-lab page.
COMP 105 Assignments
- Link to Mini-Lab 1
people.kzoo.eduserver (remember that its host name for uploading is
peopleftp.kzoo.edu). Test that the link to the Mini-Lab works on the server by clicking on it from your home page.