//function to sum numbers 1 - n; ex: 1+2+3+4+5 = 15; pass as callback;
(function(x) {
var z = (x*(x+1)/2);
//console.log(z);
}(5));
////////////////////////////////////////////////////////////////////////
////////////////////////////calc////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
var $ = function(id) {
return document.getElementById(id);
};
var buttons = ['_1','_2','_3','_4','_5','_6','_7','_8','_9','_0'];
for(var i=0, c=buttons.length;i<c;i++) {
$(buttons[i]).addEventListener('click', update, false);
}
function update() {
console.log(this.value);
$('input').value += this.value;
}
var Calc = function(a,b) {
this.a = a;
this.b = b;
};
Calc.prototype = {
constructor: Calc,
sum: function() {
return this.a + this.b;
},
subtract: function() {
return this.a - this.b;
}
};
var x = new Calc(1,2);
try { //
// var x = prompt('what the x');
if (x > 5) {
throw 'x is greater than 5';
} else if (x < 5) {
throw 'x is less than 5';
} else {
throw new Exception('x is = to 5');
}
}
catch (e) {
// console.log(e);
}
function getElementsByClassName(className) {
var results = [];
walkTheDOM(document.body, function (node) {
var a = ['one','two']; // array of class names
var c = node.className; // the node's classname
var i; // loop counter
// If the node has a class name, then split it into a list of simple names.
// If any of them match the requested name, then append the node to the set of results.
if (c) {
a = c.split(' ');
for (i = 0; i < a.length; i += 1) {
if (a[i] === className) {
results.push(node);
break;
}
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.