Console Logging on Fiddle

by TimunAb

HTML

<div id='console'></div>

JavaScript

var jsFiddleConsole = function() {
    return({
        log: function(msg) {
          consoleDiv = document.getElementById('console');
          para = document.createElement('p');
          text = document.createTextNode(msg);
          para.appendChild(text);
          consoleDiv.appendChild(para);
        }
    });
}();

jsFiddleConsole.log('hello');
jsFiddleConsole.log('world');

var myHash = {};
myHash["key1"] = "value1";
jsFiddleConsole.log(JSON.stringify(myHash));

// Literal object
var personLiteral = {
    firstName:"John",
    lastName:"Doe",
    age:50,
    eyeColor:"blue"
};
jsFiddleConsole.log(JSON.stringify(personLiteral));

var personObject = new Object();
personObject.firstName = "John";
personObject.lastName = "Doe";
personObject.age = 50;
personObject.eyeColor = "blue";
jsFiddleConsole.log(JSON.stringify(personObject));

function person(first, last, age, eye) {
    this.firstName = first;
    this.lastName = last;
    this.age = age;
    this.eyeColor = eye;
}
var myFather = new person("John", "Doe", 50, "blue");
var myMother = new person("Sally", "Rally", 48, "green");
jsFiddleConsole.log(JSON.stringify(myFather));
jsFiddleConsole.log(JSON.stringify(myMother));