Lab 6 - JavaScript Conditionals
In this lab, you’ll be creating several programs:
- cake
- spanish
- odd calculator
Summary of Commands:
THESE ARE NOT LAB INSTRUCTIONS.
The following is just a reference. The lab instructions are below.
# create a local repository
git init
# configure it with your name and email
git config user.name "your name"
git config user.email "your@email.address"
# create a remote repository
curl -u 'your github user name' https://api.github.com/user/repos -d '{"name":"your repository name"}'
# link the two
git remote add origin "your username"@"the url to your repository on github"
# two ways to show all remote repositories
git remote -v
cat .git/config
# removing a remote repository by name (usually origin)
git remote remove name_of_remote
# changing / setting the url of a named remote repository (usually origin)
git remote set-url name_of_remote new_remote_url
# look at the differences between your last save and your current changes (line by line)
git diff --color
# check on the status of your changes
git status
# "stage" or mark your changes as ready to be saved
git add --all
# save!
git commit -m 'my message'
# show a log of your changes so far
git log --color (show your changes so far)
# send to a remote repository (to submit an assignment)
git push origin master
Instructions
Note that ALL OF THESE FILES MUST BE CREATED IN THE REPOSITORY THAT YOU CREATED FOR THIS LAB.
cake
Write a program that asks the user if they want cake. Based on the response, it will output a different message to the JavaScript Console.
- using SublimeText, create a new file called cake.html in your repository directory: ~/Desktop/bzuckerman/lab-06-javascript-conditionals/
- setup an html file, and add script tags… start writing your JavaScript between the script tags
- the program should ask: “Do you want cake?”
- based on the user’s input:
- print out “Have some cake.” if the user says exactly “yes”
- print out “No cake for you.” if the user says anything other than “yes”
- example interaction is below (everything after the greater than sign (> is user input using the prompt function):
# Run 1
(prompt) Do you want cake?
> yes
Have some cake.
# Run 2
(prompt) Do you want cake?
> maybe
No cake for you.
- save your file in SublimeText
- use status, add commit and push to save your file in version control and submit it
- modify your program so that the program accepts no as an answer, and says something different if it is not yes and not no:
- print out “Have some cake.” if the user says exactly “yes”
- print out “No cake for you.” if the user says exactly “no”
- print out “I don’t understand.” if the user types anything else”
- example interaction is below (everything after the greater than sign (> is user input using the prompt function):
# Run 1
(prompt) Do you want cake?
> no
No cake for you
# Run 2
(prompt) Do you want cake?
> maybe
I don't understand
- save your file in SublimeText
- use status, add commit and push to save your file in version control and submit it
spanish
Write a program that translates english words to Spanish.
- using SublimeText, create a new file called spanish.html in your repository directory: ~/Desktop/bzuckerman/lab-06-javascript-conditionals/
- setup an html file, and add script tags… start writing your JavaScript between the script tags
- the program should ask for a word: “Give me a word in English…”
- based on the user’s input:
- output “gato” if the user says “cat”
- output “perro” if the user says “dog”
- output “caballo” if the user says “horse”
- output “no entiendo” if the user says anything else
- example interaction is below (everything after the greater than sign (> is user input using the prompt function):
# Run 1
(prompt) Give me a word in English...
> gato
cat
# Run 2
(prompt) Give me a word in English...
> bear
no entiendo
- save your file in SublimeText
- use status, add commit and push to save your file in version control and submit it `
odd calculator - oddcalc.html
Prompt the user for a number.
Prompt the user for another number.
Ask the user what kind of operation they want to do - mult, div, or mod.
- If the user says "mult", then multiply the numbers and output the result
- If the user says "div", then divide the numbers and output the result
- If the user says "mod", then modulo the numbers and output the result
- OTHERWISE, output " *** invalid operation *** "
guess *** extra credit ***
Write a number guessing game! “Hardcode” a secret number. Ask the user to guess the secret number. If they are correct, say “You got it!”. If they are within 1, say “Close, but the number is (the secret number)”. Lastly, if they were totally incorrect, then say, “The number is (the secret number)”. Look up the parseInt function to convert the input into a number so that your comparisons work.