/javascript_functions

Google x Udacity FEND L14

Primary LanguageJavaScript

#javascript_functions

Q5-1: Declare a function called laugh() that returns "hahahahahahahahahaha!". Print the value returned from the laugh() function to the console.

Q5-2: Write a function called laugh() that takes one parameter, num that represents the number of "ha"s to return. console.log(laugh(3)); Prints: "hahaha!"

Q5-3: Create a function called buildTriangle() that will accept an input (the triangle at its widest width) and will return the string representation of a triangle. See the example output below. buildTriangle(10); Returns:

* 
* * 
* * * 
* * * * 
* * * * * 
* * * * * * 
* * * * * * * 
* * * * * * * * 
* * * * * * * * * 
* * * * * * * * * *

Q5-4: Write an anonymous function expression that stores a function in a variable called "laugh" and outputs the number of "ha"s that you pass in as an argument. laugh(3); Returns: hahaha!

Q5-5: Write a named function expression that stores the function in a variable called cry and returns "boohoo!". Don't forget to call the function using the variable name, not the function name: cry(); Returns: boohoo!

Q5-6: Call the emotions() function so that it prints the output you see below, but instead of passing the laugh() function as an argument, pass an inline function expression instead. emotions("happy", laugh(2)); Prints: "I am happy, haha!"