Media Computation Skills Lab

MTEC 1003

Lab 09 - JavaScript Functions

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

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

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


Note: ALL SOLUTIONS TO THESE PROBLEMS MUST BE SHOWN IN 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

MTEC 1003 - Media Computation Skills Lab