This project is intended as an additional resource on top of the Javascript assessment practice.
- If you want more practice working with Git and Github, fork this project on GitHub and then clone your fork to your development box, so you have both your own local copy and a remote in GitHub where you can push your solutions.
- Setup your own copy of the code using the instructions above
- Read the exercise prompts listed below
- Define your functions that solve the prompts inside of
solutions.js
.
The comments to the right of the function call example demonstrate the output of the function's operation on the provided input(s). Add your function definitions to solutions.js
. Refresh index.html
to run automated tests for feedback on your solutions.
-
Define a function named
isOdd
that takes in any input and returnstrue
if the input is an odd number, returnfalse
for any other situation. You do not need to consider floating-point and decimal numbers.isOdd(3) // true isOdd(2) // false isOdd(73) // true isOdd(200) // false isOdd("23") // true isOdd("20") // false isOdd("three") // false isOdd(NaN) // false isOdd(null) // false isOdd(0) // false
-
Define a function named
isVowel
that takes in a single character and returnstrue
if the character is a vowel. *Not including the letter 'y' & 'Y'.isVowel('e') // true isVowel('u') // true isVowel('I') // true isVowel('Q') // false isVowel('Y') // false isVowel(1) // false isVowel(-1) // false isVowel(null) // false isVowel("hello") // false
-
Define a function named
combineStrings
that takes in two parameters, if both parameters are strings, then return a concatenated string of both parameters. Otherwise, returnfalse
.combineStrings("Hello", "World") // HelloWorld combineStrings("sun", "set") // sunset combineStrings("Number", 1) // false combineStrings(true, true) // false combineStrings('true', 'true') // truetrue
-
Define a function named
sumArgs
that takes in three parameters, if they are numbers then add them together. Otherwise returnfalse
.sumArgs(1, 2, 3) // 6 sumArgs("1", "2", "3") // false sumArgs("1", 2, 3) // false sumArgs(true, 2, 3) // false sumArgs(10, -2, -3) // 5 sumArgs(NaN, NaN, NaN) // NaN sumArgs([1, 2], [3,4], [5,6]) // false sumArgs(null, 1, 2 // false
-
Define a function named
truncateString
that takes in a string as the first parameter and a number as the second parameter. Truncate (shorten) the string by the length based on the argument passed in. For example, truncateString("hello world",1) would return "hello worl"truncateString("hello world", 1) // "hello worl" truncateString("superman", 3) // "super" truncateString(true, 1) // false truncateString("superman", true) // false truncateString("true", 1 // "tru" truncateString("texas", 7) // "" (empty string) truncateString("san antonio", "texas") // false truncateString("codeup", 2) // code
-
Define a function named
reverseSign
that takes in a number as the first parameter. Reverse the sign of the argument passed in, return false if the argument is not a number. For example,reverseSign(1)
would return-1
.reverseSign(1) // -1 reverseSign(-2) // 2 reverseSign("3") // -3 reverseSign("test") // false reverseSign([]) // false
-
Define a function named
makeUppercase
that takes in a string as the first parameter. Return the argument passed in entirely uppercased, return false if the argument is not a string. For example,makeUppercase("test")
would return"TEST"
.makeUppercase("doom") // DOOM makeUppercase("CoDeUp") // CODEUP makeUppercase("DONE") // DONE makeUppercase(100) // false makeUppercase(true) // false makeUppercase([]) // false
-
Define a function named
isMultiple
that takes in twonumber
parameters. Returntrue
if one argument is a multiple of the other,false
otherwise. For example,isMultiple(2, 6)
would returntrue
.isMultiple(13, 26) // true isMultiple(10, 5) // true isMultiple(5, 13) // false isMultiple(2, 3) // false isMultiple("test") // false isMultiple(100) // false isMultiple(true) // false isMultiple([]) // false
-
Define a function named
canPurchase
that takes in twonumber
parameters,billAmount
&availableCash
. Returntrue
ifavailableCash
is greater thanbillAmount
,false
otherwise. For example,canPurchase(10, 20)
would returntrue
.canPurchase(100, 250) // true canPurchase("50", "100") // true canPurchase(100, 90) // false canPurchase("80", "30") // false canPurchase() // false canPurchase("a", "b") // false
-
Define a function named
getInitials
that takes in twostring
parameters,first
&last
. Return the names combined and formatted as initials, returnfalse
if either parameter is invalid. For example,getInitials("John", "Snow")
would return"J.S."
getInitials("Daniel", "Fryar") // D.F. getInitials("David", "Stephens") // D.S. getInitials("Hung", "Ly") // H.L. getInitials("Tristan", "Crawford") // T.C. getInitials() // false getInitials(1, 2) // false getInitials("3", "4") // false
index.html
shows the ouptut from automated test datasolutions.js
is where you will write your function definitions that solve the exercises belowtests.js
is the suite of automated tests that call your functions insolutions.js
with different inputs.
Consider this example problem.
Write a function called
isBoolean
that takes in a value and returns a boolean if the argument provided is a boolean value or not.
-
isBoolean("Dog")
should returnfalse
because a string is not a boolean -
isBoolean(false)
should returntrue
because only true and false are boolean values. -
When a problem says
return
, it meansreturn
, notconsole.log
. -
When a problem says that a function will take in an input, then it means the function must be defined so that it takes in an argument as its input, rather than relying on variables defined outside the function.
The following example is incorrect because the function does not take in an argument. It's modifying a global variable, and that is not the same as accepting an input as an argument.
var input = "Grace Hopper"
function isBoolean() {
return typeof input == "boolean";
}
This is incorrect because the function doesn't return the output. Functions that do not have an explicit return
statement return undefined
by default.
function isBoolean(input) {
console.log(typeof input == 'boolean');
}
Correct solution:
function isBoolean(input) {
return typeof input == "boolean";
}
- Testing framework: Jasmine
- Made by [Hung Ly & Tristan Crawford]