Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>JS Bin</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- // Traffic Lights Exercise
- function doTrafficLights() {
- var activeLight = getActiveLight();
- if (activeLight == "green") {
- return turnGreen();
- } else if (activeLight == "red"){
- return turnRed();
- } else if (activeLight == "yellow"){
- return turnYellow();
- }
- }
- function turnOffLights() {
- $('.traffic-light').removeClass('yellow-on red-on green-on');
- }
- function turnGreen() {
- turnOffLights();
- $('.green-light').addClass('green-on');
- }
- function turnYellow() {
- turnOffLights();
- $('.yellow-light').addClass('yellow-on');
- }
- function turnRed() {
- turnOffLights();
- // Error Alert Exercise
- 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;}
- }
- }
- function reportError(e) {
- $('.js-error-report').text("Uh oh, something went wrong! Here's what we know: " + e.message);
- }
- $(main);
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">// Traffic Lights Exercise
- function doTrafficLights() {
- var activeLight = getActiveLight();
- if (activeLight == "green") {
- return turnGreen();
- } else if (activeLight == "red"){
- return turnRed();
- } else if (activeLight == "yellow"){
- return turnYellow();
- }
- }
- function turnOffLights() {
- $('.traffic-light').removeClass('yellow-on red-on green-on');
- }
- function turnGreen() {
- turnOffLights();
- $('.green-light').addClass('green-on');
- }
- function turnYellow() {
- turnOffLights();
- $('.yellow-light').addClass('yellow-on');
- }
- function turnRed() {
- turnOffLights();
- // Error Alert Exercise
- 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;}
- }
- }
- function reportError(e) {
- $('.js-error-report').text("Uh oh, something went wrong! Here's what we know: " + e.message);
- }
- $(main);</script></body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement