Lab 5 - Part 2 - JavaScript Values, Types, Operations, Variables, Calling Functions, and Input/Output
In this lab, you’ll be creating a few programs:
- greetings
- madlibs and madlibs with prompt
Instructions
Setup
Check your local repository, and start up SublimeText.
- open terminal
- go to your repository folder: /Users/bree/Desktop/bzuckerman/lab-05-javascript/
- once you’re in it, check if your repository exists by using git status:
- you should get back:
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)
- open up SublimeText
greetings
- using SublimeText, create a new file called greetings.html in your repository directory: ~/Desktop/bzuckerman/lab-05-javascript/
- setup an html file, and add script tags… start writing your JavaScript between the script tags
- ask the user for their name
- save that input in a variable
- print out to the JavaScript console “Hi (name that the user entered)!”
- save your file in SublimeText
- use status, add commit and push to save your file in version control and submit it
- example interaction is below (everything after the greater than sign (> is user input using the prompt function):
(prompt) What's your name?
> bree
Hi bree!
madlibs
Write a program that simulates MadLibs! It will ask your for words, and then it will print out a story (in this case lyrics), with the user entered words substituted for words in the story.
Part 1
- using SublimeText, create a new file called madlibs.html in your repository directory: ~/Desktop/bzuckerman/lab-05-javascript/
- setup an html file, and add script tags… start writing your JavaScript between the script tags
- define 4 variables, set them each equal to a word: a noun, an adjective, an adverb and a verb
- name the variables after the part of speech of the word they are replacing, for example
var noun = 'pizza';
var adjective = 'ridiculous';
etc...
- write program that uses those 4 variables in these lyrics:
On a tropical island,
Underneath a molten lava moon.
Hangin' with the hula dancers,
Askin' questions cause' they got all the answers.
- substitute any words you’d like to change with one of the variables you defined (make sure it's the same part of speech though! (e.g. substitute a noun with another noun, etc))
- use string concatenation to stitch together the lyrics
- print out the new version of lyrics, each line on a separate line
- for example, the JavaScript console may display:
On a tropical pizza,
Underneath a ridiculous moon ...
- save your file in SublimeText
- use status, add commit and push to save your file in version control and submit it
Part 2
- modify your program so that it asks for user input for each variable (don’t use hardcoded values anymore)
- this should result in 4 dialog boxes
- and the result of the new lyrics printed out to the JavaScript console
- save your file in SublimeText
- use status, add commit and push to save your file in version control and submit it