Skip to content

Instantly share code, notes, and snippets.

@michelleroth
Created November 13, 2016 01:00
Show Gist options
  • Save michelleroth/171e9dd2b8300a8ef5f454ba79567192 to your computer and use it in GitHub Desktop.
Save michelleroth/171e9dd2b8300a8ef5f454ba79567192 to your computer and use it in GitHub Desktop.
function doTrafficLights() {
turnOffLights();
var activeLight = getActiveLight();
if (activeLight === 'red') {
turnRed();
}
if (activeLight === 'yellow') {
turnYellow();
}
if (activeLight === 'green') {
turnGreen();
}
}
/* From here down, you are not expected to
understand.... for now :)
Nothing to see here!
*/
function turnOffLights() {
$('.traffic-light').removeClass('yellow-on red-on green-on');
}
function turnGreen() {
$('.green-light').addClass('green-on');
}
function turnYellow() {
$('.yellow-light').addClass('yellow-on');
}
function turnRed() {
$('.red-light').addClass('red-on');
}
function getActiveLight() {
return (['red', 'green', 'yellow'])[Math.floor(Math.random() * 3)];
}
function handleClicks() {
$('.js-control-lights').click(function() {
doTrafficLights();
});
}
$(function() {
handleClicks();
})
function main() {
try {
doAllTheThings();
}
catch(e) {
console.error(e);
reportError(e);
}
}
function doAllTheThings() {
throw {
message: "Everything's ruined",
name: "FatalException",
toString: function(){return this.name + ": " + this.message;}
}
}
/* From here down, you are not expected to
understand.... for now :)
Nothing to see here!
*/
function reportError(e) {
$('.js-error-report').text("Uh oh, something went wrong! Here's what we know: " + e.message);
}
$(main);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment