View sourcecode

The following files exists in this folder. Click to view.

lab.md

1 lines ASCII Unix (LF)
1
Lab questions
==============================
//Remember to include the "functions.js" before "exercise.js" in your .html-file!

1. Create a function that returns the sum of two numbers. The function should be called "sumNumbers" and take two arguments. Print out the result.

2. Create a function that returns the product of two numbers. The function should be called "productNumbers" and take two arguments. Print out the result.

3. Create a function that returns the sum of all numbers between two chosen numbers. The function should take two arguments, one representing the lowest boundary and one that represents the highest boundary. For example the arguments 10 and 20 should return the sum of 11+12+13...+19. Name the function "sumRangeNumbers" and print out the result.

4. Create a function that returns a phrase. If your name is "John", the returned phrase should be: "Hi John, how are you?". The argument should be a string that holds a name. Name the function "stringPhrase" and print out the result.

5. Create a function that gives an answer to the exact question "How are you?". The answer should be "I am fine". If the question is otherwise, the response should be "Try again". Name the function "stringResponse" and print out the result. 

6. Create a function that returns true or false (boolean) if a given number is higher than the other. The function should take two arguments, one argument that holds the value to check and another argument that holds the value to check with. For example the arguments 5 and 10 should return "false", because 5 is not higher than 10. If the arguments are 10 and 5, the result should be "true". Name the function "checkIfHigher" and print out the result. 

7. Create a function that returns all numbers comma separated, in a range of two given ones. Make sure that this time, the order of the arguments should not matter. For example if the arguments are: 5 and 10, the function should print: 5,6,7,8,9,10. If the arguments are: 10 and 5, the function should print: 10,9,8,7,6,5. If the arguments are the same, print out only that number. Name the function "printRange" and print out the result.

8. Create a function that returns a string a specific number of times. The function should take 2 arguments, one string and one number. The number represents the number of times the string should be printed out. Name the function "stringRepeat" and print out the result.

9. Create a function that returns the money you have, after years of interest, given three arguments. First argument represents the start money, the second argument represents the number of years your money produces rent. The third argument is the interest rate in percent (%). Name the function "calculateInterest" and print out the result.   

10. Create a function that returns the number of values that are between two given ones. Name the function "countNumbers" and print out the result.

11. Create a function that returns "true" if a given number is higher than 10 and less than 20. If the number is out of range, the function should return "false". The return type should be boolean. Name the function "inRange" and print out the result.

12. Create a function that takes two arguments, "start" and "stop". The arguments represents the starting point and stop point of the game "Fizz Buzz" (http://en.wikipedia.org/wiki/Fizz_buzz). The function should run from start to stop and print out "Fizz", "Buzz" or both at appropriate numbers. If "stop" is equal or lower than "start", the function should throw an exeption. Name the function "fizzBuzz" and print out the result.

------------------------------

2014-06-03 (Zingo89) PA1 First try.