Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  
</body>
</html>
 
(function($) {
  var sum = function( num1,num2 ) {
    var result = num1 + num2;
    
    // This works, but seems clunky - is there a better way?
    var name = sum.prototype.name;
  
    $(this).text( num1+' plus '+num2+' is '+result+', '+name+'.');
    return $(this);
  };
  var name = prompt('Please enter your name','');
  // Is there a better way to set this default variable?
  sum.prototype.name = name;
  $.fn.basicArithmetic = sum;
   
})(jQuery); 
// end of plugin. Example usage...
$('<p/>').basicArithmetic(1,5).appendTo('body');
$('<p/>').basicArithmetic(2,2).appendTo('body');
$('<p/>').basicArithmetic(25,30).appendTo('body');
$('<p/>').basicArithmetic(92.3,15.17).appendTo('body');
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers