Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rexfordkelly-at-makersquare/7b30f60e169f1a3dc6e54c384253cf80 to your computer and use it in GitHub Desktop.
Save rexfordkelly-at-makersquare/7b30f60e169f1a3dc6e54c384253cf80 to your computer and use it in GitHub Desktop.
Daniel Kim W2D2 Checkpoint
Daniel Kim W2D2 checkPoint
1.
function average (x,y) {// good job
return (x+y)/2;
}
2.
function greeter (name) {// good job
return "Hello, " + name + "!";
}
3.a.
function even (x) {// good job
if(x%2 === 0) {
return true;
} else {
return false;
};
};
3.b.
function odd (x) {// good job
if(x%2 === 1) {
return true;
} else {
return false;
};
};
3.c.
function positive (x) {// good job
if(x>=0) {
return true;
} else {
return false;
};
};
3.d.
function negative (x) {// good job
if(x<0) {
return true;
} else {
return false;
};
};
4.
function sayHello (language) {// good job
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) {// good job
if(username.length>=5 && password.length >=8) {
return true;
} else {
return false;
}
}
6.
function repeatString (str, count) { // good job
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) { // Almost there...
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