-
-
Save mannuelf/d6c3d970fa0a21e45b1ab04c901331b6 to your computer and use it in GitHub Desktop.
Return a singe value return a single value // source http://jsbin.com/bamefo
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 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> |
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
(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