In this activity you will modify JavaScript functions to experiment with strings, variables, and functions (both defining functions and calling them).
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.
.html
.
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)
alert
function is a "Do Something"
method (it does something for us), the prompt
function 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 alert
.
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.
madLib
function 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.
Edit the course "home page" you created in a previous activity and add a link to your MadLibs page. For example,
COMP 102 Assignments
- Link to Numbers and Strings Activity
- Link to Mad Libs Activity
In the link, refer to your new page with a relative pathname
which is just the name of the file (e.g.,
<a href="MadLibs.html">
).
This tells the browser that the file to look for is in the same
directory or folder as the current file (your main COMP 102 web page,
in this case).
You do not want to give
a full or absolute pathname, like
<a href="file:///Desktop/MadLibs.html">
,
because the location of your file on the
student.cs.kzoo.edu
server will not be the same as on
your own laptop or classroom computer.
If you worked in a team, each member of your group should do this, so each of you has a link to your MadLibs page. After the link, list your teammates in parentheses; for example, "MadLibs Activity (with Gandalf and Galadriel)".
student.cs.kzoo.edu
server.
Test that the link to this activity works on the server by clicking
on it from your home page there.
(Make sure that your browser is looking at the page on
student.cs.kzoo.edu
, not your local version.)