Commenting. Something that changes nothing and that the user never sees. However, it is in every professional webpage. Why? Comments can help readers of the code (you or other developers) understand what is being done in that section. Comments should only be used when code is non understandable without it or to mark sections of code. You should write code as if the comments are invisible. That's how it gets executed after all.
See the below links for learning about commenting:
You can utilise comments like this:
/*start JS/CSS comment
multiline JS comment / CSS comment
end JS/CSS comment*/
//single line JS comment
<!--HTML comment-->
Bonus :: Challenge One
Task: prevent background colour from becoming 'palegoldenrod'
Using the least characters (no redeclaring changeColour function)
function changeColour() {
document.body.style.backgroundColor = "palegoldenrod";
}
var counter = true;
function init() {
if ((counter || true) && changeColour) {
changeColour();
}
}
init();
Challenge Complete
");
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function setDone() {
if (getRemember()) {
if (typeof(Storage) !== "undefined") {
localStorage.setItem("b1", "1");
} else if (!navigator.cookieEnabled == "false") {
setCookie("b1", "1", 10000);
} else {
alert("Please enable cookies for full website functionality");
}
}
}
function getDone() {
if (typeof(Storage) !== "undefined") {
if (localStorage.b1 === "1") {
return true;
} else {
return false;
}
} else if (!navigator.cookieEnabled == "false") {
if (getCookie("b1") === "1") {
return true;
} else {
return false;
}
} else {
alert("Please enable cookies for full website functionality");
}
}
function getUnlocked() {
if (typeof(Storage) !== "undefined") {
if (localStorage.c13 === "1") {
return true;
} else {
return false;
}
} else if (!navigator.cookieEnabled == "false") {
if (getCookie("c13") === "1") {
return true;
} else {
return false;
}
} else {
alert("Please enable cookies for full website functionality");
}
}
if (getDone()) {
document.getElementById("original").setAttribute("hidden", "");
document.getElementById("hidden").removeAttribute("hidden");
document.getElementById("infopanel").removeAttribute("hidden");
}
function removeDone() {
if (typeof(Storage) !== "undefined") {
localStorage.removeItem("b1");
} else if (!navigator.cookieEnabled == "false") {
setCookie("b1", "1", -1);
}
location.reload();
}
document.getElementById("resetbtn").addEventListener("click", function() {
removeDone();
});
prettyPrint();
console.log("Think basics. Think blatantly obvious.");
document.getElementById("gobtn").addEventListener("click", function(){
if (document.getElementById("i1").value.indexOf("/*") >= 0 || document.getElementById("i2").value.indexOf("/*") >= 0) {
document.getElementById("original").setAttribute("hidden", "");
document.getElementById("hidden").removeAttribute("hidden");
document.getElementById("infopanel").removeAttribute("hidden");
setDone();
} else {
document.body.style.backgroundColor = "palegoldenrod";
}
});