- What is a function?
- What is a function call?
- What is a code block, and how does it relate to a function?
- Create a function that takes a string as an argument and greets the user. For example, if the function is called with "John," the function should return "Hello, John!"
- Create a function that takes a string as an argument and returns a string with the argument value in reverse. For example, if the function is called with the input "hello," the function should return "olleh." (Use a loop, not a method that does this in one step.)
- What is a default argument, and how does it work?
- What is the scope and lifetime of a variable?
- What is a return value?
- What is the return value of a function that does not have a return statement?
- Given the following function, find mistakes in the code and explain what the function is supposed to do:
function foo(x) { x * 2; } let x = 7; x = foo(x); console.log(x);
- Given the following code, find and correct the mistake in the code:
function bar(x = 8) { x += 1; } function foo() { bar(); x *= 2; } let x = 7; foo(x); console.log(x); // x should change!
- Given the following function, what is the return value of the function call
foo(2)
? Explain your answer.function foo(x) { if (x > 5) { return x; } else { return x + foo(x + 1); } }
- Create a function that takes an array of numbers as an argument and returns the sum of the odd numbers in the array. (Use a loop, not a method that does this in one step.)
- Create a function that takes a string as an argument and returns a boolean, true if string is a palindrome else false. A palindrome is a word that reads the same backward as forward. For example, if the function is called with
"hello"
it should returnfalse
, if the function receives"elle"
it should returntrue
, becauseelle
backwards is alsoelle
.
generated from JavaScriptADI/assignment-functions
-
Notifications
You must be signed in to change notification settings - Fork 5
JavaScriptADI/javascript191-assignment-7-assignment-functions
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
javascript191-assignment-7-assignment-functions created by GitHub Classroom
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published