Lab 6 / Part 1 - JavaScript Basics
In this lab, you’ll be creating several programs:
- say twice
- shout
- temperature
- miles
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-06-review 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.
say twice
Write a program that takes user input and repeats the user input twice (both words on the same line) in the JavaScript console.
- using your text editor (e.g. Atom, Sublime Text, etc.), create a new file called saytwice.html in your repository directory: ~/Desktop/myClasses/mtec1003/lab-06-review/
- 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 to say twice”
- the program should repeat the input twice on the same line with a space inbetween… back to the JavaScript console
- for example, if someone enters “hello” in the prompt dialog
- the output in the console would be “hello hello”
- example interaction is below (everything after the greater than sign (> is user input using the prompt function):
(prompt) Give me a word to say twice
> hello
hello hello
- 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
shout
Write a program that takes user input and repeats the user input, but with three exclamation points afterwards.
- using your text editor (e.g. Atom, Sublime Text, etc.), create a new file called shout.html in your repository directory: ~/Desktop/myClasses/mtec1003/lab-06-review/
- 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, and I’ll shout it out”
- the program should repeat the word, but with three exclamation points added to it
- the output should go to the JavaScript console
- example interaction is below (everything after the greater than sign (> is user input using the prompt function):
(prompt) Give me a word, and I'll shout it out
> yeah
yeah!!!
- 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
temperature
Write a program that calculates celsius to fahrenheit based on user input.
- using your text editor (e.g. Atom, Sublime Text, etc.), create a new file called temperature.html in your repository directory: ~/Desktop/myClasses/mtec1003/lab-06-review/
- setup an html file, and add script tags… start writing your JavaScript between the script tags
- the program should ask for the temperature in celsius
- find the formula for celsius to faahrenheit conversion online!
- translate that formula into javascript
- the program should output to the JavaScript console: c degrees celsius is f degrees fahrenheit
- (obvs with f and c substituted with the appropriate calculated values)
- example interaction is below (everything after the greater than sign (> is user input using the prompt function):
(prompt) Please enter a temperature in celsius
> 37
37 degrees celsius is 98 degrees fahrenheit
- 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
miles
Write a program that calculates miles-per-gallon based on user input for miles driven and gallons of gas used.
- using your text editor (e.g. Atom, Sublime Text, etc.), create a new file called miles.html in your repository directory: ~/Desktop/myClasses/mtec1003/lab-06-review/
- setup an html file, and add script tags… start writing your JavaScript between the script tags
- miles-per-gallon (mpg) can be calculated using the following formula…
- mpg = miles driven / gallons of gas used
- ask the user for the number of miles driven and the gallons of gas used
- calculate miles-per-gallon and output the result to the JavaScript console
- example interaction is below (everything after the greater than sign (> is user input using the prompt function):
(prompt) How many miles did you drive?
>20
(prompt) How many gallons of gas did you use?
>2
Your car gets 10.0 miles per gallon.
- 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