Media Computation Skills Lab

MTEC 1003 - Fall 2016

Lab 6 - JavaScript Basics

In this lab, you’ll be creating several programs:

  1. say twice
  2. shout
  3. temperature
  4. miles
  5. * …and a couple of challenging ones: numbers and tree

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.

say twice

Write a program that takes user input and repeats the user input twice (both words on the same lin) in the JavaScript console.

(prompt) Give me a word to say twice
> hello
hello hello

shout

Write a program that takes user input and repeats the user input, but with three exclamation points afterwards.

(prompt) Give me a word, and I'll shout it out
> yeah
yeah!!!

temperature

Write a program that calculates celsius to fahrenheit based on user input.

(prompt) Please enter a temperature in celsius
> 37
37 degrees celsius is 98 degrees fahrenheit

miles

Write a program that calculates miles-per-gallon based on user input for miles driven and gallons of gas used.

(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.

*numbers

(This one’s hard!) Write a program that outputs the number in the thousands, hundreds, tens and ones places of a number.

(prompt) Please enter a number
> 256

0 thousands
2 hundreds
5 tens
6 ones

*tree

(This one’s slightly hard… try doing it in just one line!) Print out a tree!

   /\
  /  \
  /  \
 /____\
   ||

MTEC 1003 - Media Computation Skills Lab 2 - Spring 2015