Created
January 15, 2017 16:54
-
-
Save bflannery/a7894468d26cd34fe6b370a9fefa9916 to your computer and use it in GitHub Desktop.
Compare the values of 2 arrays
This file contains 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
//Compare the values of 2 arrays. | |
//If Alice[i] > Bob[i], then Alice is awarded 1 point. | |
//If Alice[i] < Bob[i] , then Bob is awarded 1 point. | |
//If Alice[i] = Bob[i], then neither person receives a point. | |
function compArr(alice , bob){ | |
alicePoints = 0; | |
bobPoints= 0; | |
for(i=0; i < 3; i++){ | |
console.log(alice[i]); | |
console.log(bob[i]); | |
if(alice[i] < bob[i]) { | |
bobPoints += 1; | |
} else if (alice[i] > bob[i]) { | |
alicePoints += 1; | |
} | |
} | |
return 'AlicePoints = ' + alicePoints + ' ' + 'BobPoints = ' + bobPoints; | |
} | |
console.log(compArr([5,6,7],[3,6,10])); | |
console.log(compArr([32,0,19],[10,7,100])); | |
console.log(compArr([8,510,32],[9,12,98])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment