Created
May 25, 2016 20:28
-
-
Save anonymous/818f79053809a51ee06ca4652a82ffd3 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/nifozis
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
body { | |
background-color: #fff; | |
} | |
</style> | |
</head> | |
<body> | |
HERE IS SOME TEXT | |
<script id="jsbin-javascript"> | |
var gameController = { | |
scores:[20, 34, 55, 46, 77], | |
avgScore: null, | |
players: [ | |
{name: "Tommy", playerID: 987, age: 23}, | |
{name: "Paul", playerID: 87, age: 33} | |
] | |
}; | |
var appController = { | |
scores: [900, 845, 809, 950], | |
avgScore: null, | |
avg: function() { | |
var sumOfScores = this.scores.reduce(function(prev, cur, index, array) { | |
return prev + cur; | |
}); | |
this.avgScore = sumOfScores / this.scores.length; | |
} | |
}; | |
appController.avg.apply(gameController, gameController.scores); | |
console.log(gameController.avgScore); | |
console.log(appController.avgScore); | |
</script> | |
<script id="jsbin-source-css" type="text/css">body { | |
background-color: #fff; | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var gameController = { | |
scores:[20, 34, 55, 46, 77], | |
avgScore: null, | |
players: [ | |
{name: "Tommy", playerID: 987, age: 23}, | |
{name: "Paul", playerID: 87, age: 33} | |
] | |
}; | |
var appController = { | |
scores: [900, 845, 809, 950], | |
avgScore: null, | |
avg: function() { | |
var sumOfScores = this.scores.reduce(function(prev, cur, index, array) { | |
return prev + cur; | |
}); | |
this.avgScore = sumOfScores / this.scores.length; | |
} | |
}; | |
appController.avg.apply(gameController, gameController.scores); | |
console.log(gameController.avgScore); | |
console.log(appController.avgScore);</script></body> | |
</html> |
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
body { | |
background-color: #fff; | |
} |
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
var gameController = { | |
scores:[20, 34, 55, 46, 77], | |
avgScore: null, | |
players: [ | |
{name: "Tommy", playerID: 987, age: 23}, | |
{name: "Paul", playerID: 87, age: 33} | |
] | |
}; | |
var appController = { | |
scores: [900, 845, 809, 950], | |
avgScore: null, | |
avg: function() { | |
var sumOfScores = this.scores.reduce(function(prev, cur, index, array) { | |
return prev + cur; | |
}); | |
this.avgScore = sumOfScores / this.scores.length; | |
} | |
}; | |
appController.avg.apply(gameController, gameController.scores); | |
console.log(gameController.avgScore); | |
console.log(appController.avgScore); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment