Skip to content

Instantly share code, notes, and snippets.

/index.html

Created May 25, 2016
Embed
What would you like to do?
JS Bin // source http://jsbin.com/nifozis
<!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>
body {
background-color: #fff;
}
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
You can’t perform that action at this time.