-
-
Save rexfordkelly-at-makersquare/6126453fad3cdb44bd9a5f2756a2bff8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 1. Write a function average that takes two numbers as input (parameters), and returns the average of those numbers. */ | |
var average = function(x , y){ // Good Job! | |
return (x+y)/2; // Try and keep your spacing consistant. | |
}; | |
/* 2. Write a function greeter that takes a name as an argument and greets that name by returning something along the lines of "Hello, <name>!" */ | |
var greeter = function(name){ // Good Job! | |
return "Hello, " + name + "!"; | |
}; | |
/* 3. Write the following functions that each accept a single number as an argument: | |
even: returns true if its argument is even, and false otherwise. | |
odd: the opposite of the above. | |
positive: returns true if its argument is positive, and false otherwise. | |
negative: the opposite of the above. */ | |
var isEven = function(x){ // Good Job!, you should keep your spacing consistant... look at line 21, and the x%2 expression. | |
if(x%2 == 0){ | |
return true; | |
}else{ | |
return false; | |
} | |
}; | |
var isOdd = function(x){ // Good Job!, you should keep your spacing consistant... | |
if(x%3 == 1){ | |
return true; | |
}else{ | |
return false; | |
} | |
}; | |
var isPositive = function(x){ | |
if(x > 0){ | |
return true; | |
}else{ | |
return false; | |
} | |
}; | |
var isNegative = function(x){ | |
if(x < 0){ | |
return true; | |
}else{ | |
return false; | |
} | |
}; | |
/* 4. Write a function sayHello that takes a language parameter, and returns "hello" in that language. Make the function work with at least three languages.*/ | |
var sayHello = function(language){ // Good Job!, nice use of the Switch statment. | |
switch(language){ | |
case "Romanian": | |
return "Buna Ziua!"; | |
case "German": | |
return "Hallo!"; | |
case "Spanish": | |
return "Hola!"; | |
default: | |
return "Sorry, don't know the greeting in that language"; | |
} | |
}; | |
/* 5. Write a function validCredentials that accepts two parameters: username and password, and returns true if both are long enough, and false otherwise. You can decide what constitutes "long enough". */ | |
function validCredentials(username, password){ // Good Job | |
if(username.length && password.length == 20){ | |
return true; | |
}else{ | |
return false; | |
} | |
}; | |
/* 6. Repeating a String n Times: Let's write a function called repeatString that takes two parameters: a string str, which is the string to be repeated, and count -- a number representing how many times the string str should be repeated, e.g.*/ | |
function repeatString(str, count){ // Sure, that works, try and redo this without using str.repeat(); | |
return str.repeat(count); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment