Created
August 24, 2016 04:40
-
-
Save dkim627/6a8d8d4733400658f1cb14bd00ea7ce3 to your computer and use it in GitHub Desktop.
Daniel Kim W2D2 Checkpoint
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
Daniel Kim W2D2 checkPoint | |
1. | |
function average (x,y) { | |
return (x+y)/2; | |
} | |
2. | |
function greeter (name) { | |
return "Hello, " + name + "!"; | |
} | |
3.a. | |
function even (x) { | |
if(x%2 === 0) { | |
return true; | |
} else { | |
return false; | |
}; | |
}; | |
3.b. | |
function odd (x) { | |
if(x%2 === 1) { | |
return true; | |
} else { | |
return false; | |
}; | |
}; | |
3.c. | |
function positive (x) { | |
if(x>=0) { | |
return true; | |
} else { | |
return false; | |
}; | |
}; | |
3.d. | |
function negative (x) { | |
if(x<0) { | |
return true; | |
} else { | |
return false; | |
}; | |
}; | |
4. | |
function sayHello (language) { | |
if (language ==="english") { | |
return "Hello!"; | |
} | |
if (language ==="spanish") { | |
return "Hola!"; | |
} | |
if (language ==="french") { | |
return "Bon Jour!"; | |
} else { | |
return "Try again, sucka!" | |
}; | |
}; | |
5. | |
function validCredentials (username, password) { | |
if(username.length>=5 && password.length >=8) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
6. | |
function repeatString (str, count) { | |
if(count===0) { | |
return ""; | |
} else { | |
var s = ""; | |
for(i=0;i<=count;i++) { | |
s=s+str; | |
return str + repeatString(str, count - 1) | |
} | |
} | |
} | |
7. | |
function average (array) { | |
var start = 0; | |
for(i=0; i<=array.length; i++) { | |
start=start+array[i]; | |
} | |
return start/array.length; | |
} | |
average([9, 8, 7]); | |
PROBLEM: RESULT COMES BACK AS "NaN" | |
8. | |
function countWords (str) { | |
var x = str.split(" ") | |
var y =x.length | |
var z = | |
for(i=0; i<=y; i++) { | |
console.log(x[i]); | |
} | |
} | |
countWords("dd dfdfd fddf dfdf df") | |
!!!NOT COMPLETE!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment