Lab 5 - Part 1 - 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
Let's start with a simplified way of setting up a new repository...
ProTip: Bookmark the following page so that you can easily repeat these steps in your future labs!
Cloning a Remote Repo Using Your GitHub API Access Token
Once you've completed the steps at the link above, you're ready to write some JavaScript.
Open up your text editor (e.g. Atom, Sublime Text, etc.)...
Note: ALL FILES YOU CREATE BELOW MUST BE SUBMITTED IN YOUR NEW REPOSITORY THIS WEEK.
greetings
- using your text editor (e.g. Atom, Sublime Text, etc.), create a new file called greetings.html in your repository directory: ~/Desktop/myClasses/mtec1003/lab-05-js-py/
- 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 your text editor (e.g. Atom, Sublime Text, etc.)
- 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 your text editor (e.g. Atom, Sublime Text, etc.), create a new file called madlibs.html in your repository directory: ~/Desktop/myClasses/mtec1003/lab-05-js-py/
- 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 your text editor (e.g. Atom, Sublime Text, etc.)
- 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 your text editor (e.g. Atom, Sublime Text, etc.)
- use status, add commit and push to save your file in version control and submit it