Lab 7 / Part 1 - JavaScript Conditionals
In this lab, you’ll be creating several programs:
- cake
- spanish
- odd calculator
Instructions
Setup
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
- On GitHub, create and name your new repository lab-07-conditionals and clone it inside your /mtec1003 folder.
- Once you've completed the steps at the link above, you're ready to begin.
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.
cake
Write a program that asks the user if they want cake. Based on their response, it should output a different message to the JavaScript Console.
- using your text editor (e.g. Atom, Sublime Text, etc.), create a new file called cake.html in your repository directory: ~/Desktop/myClasses/mtec1003/lab-07-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 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
- 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 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
spanish
Write a program that translates english words to Spanish.
- using your text editor (e.g. Atom, Sublime Text, etc.), create a new file called spanish.html in your repository directory: ~/Desktop/myClasses/mtec1003/lab-07-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 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 `
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 - mul, div, or mod.
- If the user says "mul", 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 *** "
MTEC 1003 - Media Computation Skills Lab