Skip to content

Instantly share code, notes, and snippets.

@tlicata
Created July 9, 2014 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tlicata/ba0bb618f74394996aed to your computer and use it in GitHub Desktop.
Save tlicata/ba0bb618f74394996aed to your computer and use it in GitHub Desktop.
Lab for Intro to Functions

Functions - Problem Set

Say Hello

Write a function called sayHello. The function should console log

Hello World

Say Hello, Name.

Write a function called sayHelloFriend. The function should take a person's name as a parameter and console log

Hello, [name]

Return Hello, Name.

Write a function called returnHello. The function should take a person's name as a paramter and return the string:

"Hello, [name]"

Greet And Reply

Write a function called greetAndReply. The function should take a person's name as a parameter, and take your name as a second parameter also. The function should then return the following string:

"Hello, [name1].  My name is [name2]."

Make sure to write this function using the previous function. That way, we don't have to write the same code twice.

Letter Count

Given a string, write a function that finds out how many times a character occurs. For example, the string "apple" would print the following:

a - 1
p - 2
l - 1
e - 1

BONUS: Make sure that lower case letters and upper case letters count for the same character. Also, ignore spaces and punctuation.

Merge

Write a function called merge. The function should take two sorted arrays of numbers as input and return a merged array of the sorted numbers from the input. For example, if the input arrays were var arr1 = [3,6,11]; var arr2 = [2,4,5,8,9]; Then the returned array would be: [2,3,4,5,6,8,9,11].

Guessing Game

Write a guessing game in which the program picks a number between 1 and 100. Have the user submit guesses. The program should tell the user if he is correct, if the actual number is higher, or if the actual number is lower.

HINT: Your program will need to generate a random number or it won't be that fun. Look up how to do that in the MDN docs for Math.random.

HINT: You will need to get input from the user. Look at the readline docs to see how it can be done in node.

HINT: Try to break this up into functions so that your code is logically separated and nothing gets repeated. For example, it would probably be nice to have a function that gets input from the user given a prompt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment