Skip to content

Instantly share code, notes, and snippets.

Created April 21, 2016 09:46
Show Gist options
  • Save anonymous/c6bb66f965ac9bd4b0cae6f5933a0f64 to your computer and use it in GitHub Desktop.
Save anonymous/c6bb66f965ac9bd4b0cae6f5933a0f64 to your computer and use it in GitHub Desktop.
Return a singe value return a single value // source http://jsbin.com/bamefo
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="return a single value ">
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Return a singe value</title>
</head>
<body>
<h1>Returning a single value </h1>
<div>5</div>
<div>3</div>
<div>78</div>
<div>22</div>
<div>1</div>
<div>2</div>
<script id="jsbin-javascript">
(function($){
$.fn.average = function() {
var sum = 0;
this.each(function() {
sum += parseFloat($(this).html());
});
return sum / $(this).length;
};
})(jQuery);
$(function() {
console.log($('div').average());
});
</script>
<script id="jsbin-source-javascript" type="text/javascript">(function($){
$.fn.average = function() {
var sum = 0;
this.each(function() {
sum += parseFloat($(this).html());
});
return sum / $(this).length;
};
})(jQuery);
$(function() {
console.log($('div').average());
});</script></body>
</html>
(function($){
$.fn.average = function() {
var sum = 0;
this.each(function() {
sum += parseFloat($(this).html());
});
return sum / $(this).length;
};
})(jQuery);
$(function() {
console.log($('div').average());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment