Media Computation Skills Lab

MTEC 1003 - Spring 2015

Lab 10 - JavaScript Functions

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

  1. greetings
  2. pluralize
  3. double
  4. factorial
  5. trees

Instructions

ALL OF THESE FILES MUST BE CREATED IN THE LAB 10 REPOSITORY THAT YOU CREATED FOR THIS LAB

Note that ALL SOLUTIONS TO THESE PROBLEMS MUST BE SHOW THE FORM OF A FUNCTION DEFINITION AND A CALL TO THAT FUNCTION.


greetings

Write a program that says hello three times.

hello
hello
hello
hello
hello

pluralize

Write a program that creates a plural version of a word inputted by a user.

(prompt) Word please:
> car
cars

double

Write a program that calculates the twice of a number entered by the user and prints it to the console log. The function should be called - double(n). First define the function. Then ask the user for a input of a number to be doubled. Then parseInt that input value and then use it in a function call to double(n).


factorial

Write a program that calculates the factorial of a number entered by the user. Factorial is the product of all positive integers less than or equal to a number. 4! (or 4 factorial) = 4 * 3 * 2 * 1 = 24

(prompt) Number please:
> 4
24

trees

Write a program that draw the number of trees that the user inputs. Ask the user how many trees he/she wants, and draw that number. Its up to you to design and style what kind of tree to draw.

MTEC 1003 - Media Computation Skills Lab - Spring 2015