working on it ...

Filters

Explore Public Snippets

Sort by

Found 577 snippets

    public by JKCPR modified May 12, 2017  180  0  4  1

    is your DOM classy? Wouldn't your console like to know...

    Intended as Dev Tool to be utilised in the browser console so that refactoring your messy CSS can be less hurty.
    ;( 
      function (){
      "use strict";
    
      //get ALL DOM elements => BODY > *, BODY *
      var elms = document.body.getElementsByTagName("*"),
          i = elms.length,
          arr = [],
          classArray;
      
      //iterate, isolate, finally indicate
      while( i-- ) {
          classArray = elms[i].className.split(/\s+/);
          if (classArray.length > 1) {
              arr.push( classArray[1] );
          }
      }
      
      console.log( arr.join(',') );
      return arr;
      
    })();

    public by jbaro modified Oct 25, 2016  4841  0  4  0

    customize embebed google maps

    /*********
    ******** params:
    ** lat: latitude
    ** lng:longitude
    ** elid: id of container
    ** iconpath: path to marker icon if necesary
    ** style: styles json
    ******** Note:
    ** You need to load google map library
    ** <script src="https://maps.googleapis.com/maps/api/js?key=YOURAPIKEY"><\/script>
    ***********/
    
    
    function initMap(lat,lng,elid,iconpath,style) {
    
    	// Create an array of styles.
    	var styles = style;
    	// Create a new StyledMapType object, passing it the array of styles,
    	// as well as the name to be displayed on the map type control.
    	var styledMap = new google.maps.StyledMapType(styles,{name: "Styled Map"});
    	// Create a map object, and include the MapTypeId to add
    	// to the map type control.
    	var myLatLng = new google.maps.LatLng(lat,lng);
    	var mapOptions = {
    		zoom: 11,
    		center: myLatLng,
    		disableDefaultUI: true,//avoid controls
    		scrollwheel: false,//avoid scrollwheel zoom
    		//draggable: false,//avoid draggable map
    		mapTypeControlOptions: {
    			mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'map_style']
    		}
    	};
    	var map = new google.maps.Map(document.getElementById(elid),mapOptions);
    	if(iconpath){
    		var marker = new google.maps.Marker({
    		  position: myLatLng,
    		  map: map,
    		  icon: iconpath
    		});
    	}
    	//Associate the styled map with the MapTypeId and set it to display.
    	map.mapTypes.set('map_style', styledMap);
    	map.setMapTypeId('map_style');
    }
    
    //silver styles example
    var mapsbw = [
    		{
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#f5f5f5"
    			}
    		  ]
    		},
    		{
    		  "elementType": "labels.icon",
    		  "stylers": [
    			{
    			  "visibility": "off"
    			}
    		  ]
    		},
    		{
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#616161"
    			}
    		  ]
    		},
    		{
    		  "elementType": "labels.text.stroke",
    		  "stylers": [
    			{
    			  "color": "#f5f5f5"
    			}
    		  ]
    		},
    		{
    		  "featureType": "administrative.land_parcel",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#bdbdbd"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#eeeeee"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#757575"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi.park",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#e5e5e5"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi.park",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#9e9e9e"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#ffffff"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.arterial",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#757575"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.highway",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#dadada"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.highway",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#616161"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.local",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#9e9e9e"
    			}
    		  ]
    		},
    		{
    		  "featureType": "transit.line",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#e5e5e5"
    			}
    		  ]
    		},
    		{
    		  "featureType": "transit.station",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#eeeeee"
    			}
    		  ]
    		},
    		{
    		  "featureType": "water",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#c9c9c9"
    			}
    		  ]
    		},
    		{
    		  "featureType": "water",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#9e9e9e"
    			}
    		  ]
    		}
    	  ];
    //init example
    initMap(42.8107705, -1.6616108,'map','./img/gm_marker.png',mapsbw);
    
                                  

    public by jbaro modified Oct 25, 2016  332498  8  2  0

    Google maps customized

    Load a google map customized
    /*********
    lat: latitude
    lng:longitude
    elid: id of container
    iconpath: path to marker icon if necesary
    style: styles json
    ***********/
    
    
    function initMap(lat,lng,elid,iconpath,style) {
    
    	// Create an array of styles.
    	var styles = style;
    	// Create a new StyledMapType object, passing it the array of styles,
    	// as well as the name to be displayed on the map type control.
    	var styledMap = new google.maps.StyledMapType(styles,{name: "Styled Map"});
    	// Create a map object, and include the MapTypeId to add
    	// to the map type control.
    	var myLatLng = new google.maps.LatLng(lat,lng);
    	var mapOptions = {
    		zoom: 11,
    		center: myLatLng,
    		mapTypeControlOptions: {
    			mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'map_style']
    		}
    	};
    	var map = new google.maps.Map(document.getElementById(elid),mapOptions);
    	if(iconpath){
    		var marker = new google.maps.Marker({
    		  position: myLatLng,
    		  map: map,
    		  icon: iconpath
    		});
    	}
    	//Associate the styled map with the MapTypeId and set it to display.
    	map.mapTypes.set('map_style', styledMap);
    	map.setMapTypeId('map_style');
    }
    
    //silver styles example
    var mapsbw = [
    		{
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#f5f5f5"
    			}
    		  ]
    		},
    		{
    		  "elementType": "labels.icon",
    		  "stylers": [
    			{
    			  "visibility": "off"
    			}
    		  ]
    		},
    		{
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#616161"
    			}
    		  ]
    		},
    		{
    		  "elementType": "labels.text.stroke",
    		  "stylers": [
    			{
    			  "color": "#f5f5f5"
    			}
    		  ]
    		},
    		{
    		  "featureType": "administrative.land_parcel",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#bdbdbd"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#eeeeee"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#757575"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi.park",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#e5e5e5"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi.park",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#9e9e9e"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#ffffff"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.arterial",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#757575"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.highway",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#dadada"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.highway",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#616161"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.local",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#9e9e9e"
    			}
    		  ]
    		},
    		{
    		  "featureType": "transit.line",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#e5e5e5"
    			}
    		  ]
    		},
    		{
    		  "featureType": "transit.station",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#eeeeee"
    			}
    		  ]
    		},
    		{
    		  "featureType": "water",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#c9c9c9"
    			}
    		  ]
    		},
    		{
    		  "featureType": "water",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#9e9e9e"
    			}
    		  ]
    		}
    	  ];
    //init example
    initMap(42.8107705, -1.6616108,'map','./img/gm_marker.png',mapsbw);

    public by jbaro modified Oct 25, 2016  548  8  3  0

    Google maps customized

    Load a google map customized
    /*********
    lat: latitude
    lng:longitude
    elid: id of container
    iconpath: path to marker icon if necesary
    style: styles
    ***********/
    
    
    function initMap(lat,lng,elid,iconpath,style) {
    
    	// Create an array of styles.
    	var styles = style;
    	// Create a new StyledMapType object, passing it the array of styles,
    	// as well as the name to be displayed on the map type control.
    	var styledMap = new google.maps.StyledMapType(styles,{name: "Styled Map"});
    	// Create a map object, and include the MapTypeId to add
    	// to the map type control.
    	var myLatLng = new google.maps.LatLng(lat,lng);
    	var mapOptions = {
    		zoom: 11,
    		center: myLatLng,
    		mapTypeControlOptions: {
    			mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'map_style']
    		}
    	};
    	var map = new google.maps.Map(document.getElementById(elid),mapOptions);
    	if(iconpath){
    		var marker = new google.maps.Marker({
    		  position: myLatLng,
    		  map: map,
    		  icon: iconpath
    		});
    	}
    	//Associate the styled map with the MapTypeId and set it to display.
    	map.mapTypes.set('map_style', styledMap);
    	map.setMapTypeId('map_style');
    }
    
    //silver styles example
    var mapsbw = [
    		{
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#f5f5f5"
    			}
    		  ]
    		},
    		{
    		  "elementType": "labels.icon",
    		  "stylers": [
    			{
    			  "visibility": "off"
    			}
    		  ]
    		},
    		{
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#616161"
    			}
    		  ]
    		},
    		{
    		  "elementType": "labels.text.stroke",
    		  "stylers": [
    			{
    			  "color": "#f5f5f5"
    			}
    		  ]
    		},
    		{
    		  "featureType": "administrative.land_parcel",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#bdbdbd"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#eeeeee"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#757575"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi.park",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#e5e5e5"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi.park",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#9e9e9e"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#ffffff"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.arterial",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#757575"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.highway",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#dadada"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.highway",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#616161"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.local",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#9e9e9e"
    			}
    		  ]
    		},
    		{
    		  "featureType": "transit.line",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#e5e5e5"
    			}
    		  ]
    		},
    		{
    		  "featureType": "transit.station",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#eeeeee"
    			}
    		  ]
    		},
    		{
    		  "featureType": "water",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#c9c9c9"
    			}
    		  ]
    		},
    		{
    		  "featureType": "water",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#9e9e9e"
    			}
    		  ]
    		}
    	  ];
    //init example
    initMap(42.8107705, -1.6616108,'map','./img/gm_marker.png',mapsbw);

    public by bablefish modified Feb 11, 2016  2229  0  6  0

    Set selected option in a valuelist

    Using a javascript function with the leave code number as a parameter, how do I select the appropriate option in the list?
    function SelectElement(valueToSelect)
    {    
        var element = document.getElementById('leaveCode');
        element.value = valueToSelect;
    }

    external by Sanix-Darker modified yesterday at 2:19:26 PM  1  0  1  0

    [JS]Fixed a div when scroll

    [JS]Fixed a div when scroll: [JS]Fixed a div when scroll
    $.fn.followTo = function (pos) {
        var $this = this,
            $window = $(window);
    
        $window.scroll(function (e) {
            if ($window.scrollTop() > pos) {
    
                $this.css({
                    position: 'fixed',
                    top: 0
                });
    
            } else {
            	$this.removeAttr('style');
            }
        });
    };
    // Calling the function
    $('#div').followTo(50);
    
    
    

    external by Illia Osmanov modified Sunday at 1:53:59 AM  2  0  1  0

    offCanvas navigation Vanilla JS

    offCanvas navigation Vanilla JS: offCanvas
    function Navigation(navObj) {
      this.btn = document.getElementById(navObj.btnId)
      this.nav = document.getElementById(navObj.navigationId)
      this.overlay = document.createElement('div')
    
      this.openNav_ = () => {
        document.body.appendChild(this.overlay)
        setTimeout(() => this.nav.classList.add(navObj.activeNavClass), 200)
      }
      this.hideNav_ = event => {
        if (document.querySelector(`.${navObj.overlayClass}`) && event.keyCode === 27 || event.type === 'click' || event.type === 'dragend') {
            this.nav.classList.remove(navObj.activeNavClass)
            if (this.nav.hasAttribute('style')) {
                this.nav.removeAttribute('style')
            }
            setTimeout(() => document.body.removeChild(this.overlay), 200)
        }
      }
      this.dragStart_ = e => {
        let start = 270 - e.screenX
        if( start < 270 ) this.nav.style.transform = `translateX(${-start}px)`
      }
    
      this.events_ = () => {
        this.btn.addEventListener('click', this.openNav_);
        this.overlay.addEventListener('click', this.hideNav_);
        window.addEventListener('keyup', this.hideNav_);
        this.nav.addEventListener('drag', this.dragStart_);
        this.nav.addEventListener('dragend', this.hideNav_);
      }
      this.init_ = () => {
        this.events_();
        this.overlay.classList.add(navObj.overlayClass);
        console.log(navObj.navigationId)
      }
      this.init_();
    }
    
    const nav = {
      btnId: 'nav-btn',
      navigationId: 'navigation',
      activeNavClass: 'active-navigation',
      overlayClass: 'overlay'
    }
    
    const offCanvas = new Navigation(nav);
    
    

    external by dyee00 modified Saturday at 7:26:30 PM  2  0  1  0

    JS Project 1

    JS Project 1: jsProject1
    // JS Project #1
    
    // Group 1 - Data
    // HUBOT_SLACK_TOKEN=xoxb-254477195828-yKXenoY5BXI6pZibTVlrhbxr ./bin/hubot --adapter slack
    
    
    ***************************  READ ME  ******************************************
    
    
    ********************************************************************************
    
    
    #1 - Random yo momma jokes
    
    Description: Hubot will tell a random "yo momma" joke when prompted.
    
    Instructions:  Ask @Data the following questions to generate a response:
    
      Type: Tell me a yo momma joke
    
    This will return a response of a random "yo momma" joke based on an array of 6 jokes.
    
    
    ********************************************************************************
    
    
    #2 - World's Top 25 Most Livable Cities
    
    Description: Hubot will list the top 25 livable cities around the world based on Monocle magazine's Quality of Life Survey of 2017.
    
    Instructions:  Ask @Data the following questions to generate a response:
    
      Type: Where are the world's most livable cities for 2017?
    
    This will return a response with a list of the 25 cities based on an array as well as a link to a video explanation of the ranking.
    
      Type(any of questions below):
         Are there any cities from Asia?
         Are there any cities from Europe?
         Are there any cities from Australia?
         Are there any cities from North America?
         Are there any cities from South America?
         Are there any cities from Africa?
         Are there any cities from Antartica?
    
    This will return a response listing all the cities from the list according to their location by continents.
    This is retrieved from an array and uses array.length.
    
    
    ********************************************************************************
    
    
    #3 - Rock, Paper, Scissors Game
    
    Description: Challenge @Data to a game of rock, paper, scissors.
    
    Instructions: Ask Hubot the following items below to play a game of rock, paper, scissors:
    
      Type: Let's play rock, paper, scissors
    
    This will return a response as well as the instructions for the game
    
      Type: I choose ____
    
    Type either rock, paper or scissors after the phrase "I choose " and this will
    return a response of what @Data has chosen and will also declare a winner.
    @Data's choices are based on a math.random code, the messages returned are based
    on if/else statements.
    
    ***************************  READ ME END ******************************************
    
    // ********************************************************************************
    // ********************************************************************************
    // ********************************************************************************
    
    
    
    
    // Code Starts below
    
    // ********************************************************************************
    
    module.exports = function(bot) {
    
    
    // #1 - "Random yo momma jokes" - start
    
    bot.hear(/Tell me a yo momma joke/i, function(res) {
    
        var randomJoke = function () { //randomJoke function starts
    
            var jokes = [
                "Yo momma is so fat when she got on the scale it said, \"I need your weight not your phone number.\"",
                "Yo momma is so fat she takes selfies in panoramic mode.",
                "Yo momma is so stupid she brought a spoon to the super bowl.",
                "Yo momma is so dumb that it takes her 2 hours to watch 60 Minutes.",
                "Yo momma is so ugly, her portraits hang themselves.",
                "Yo momma is so ugly, when she threw a boomerang, it wouldn't come back."
            ];
    
            var yoMomma = jokes[Math.floor(Math.random() * jokes.length)];
            return yoMomma;
        }; //randomJoke function ends
    
        return res.send("Here's one -  " + randomJoke() );
    
    }); // end - random yo momma jokes
    
    
    // ********************************************************************************
    
    
    // #2 - World’s Top 25 Most Livable Cities for 2017
    
    
      var cities = ["1. Tokyo", "2. Vienna", "3. Berlin",
                    "4. Munich","5. Melbourne","6. Copenhagen",
                    "7. Sydney", "8. Zürich", "9. Hamburg", "10. Madrid",
                    "11. Stockholm", "12. Kyoto", "13. Helsinki", "14. Fukuoka",
                    "15. Hong Kong", "16. Lisbon", "17. Barcelona", "18. Vancouver",
                    "19. Dusseldorf", "20. Amsterdam", "21. Singapore",
                    "22. Auckland", "23. Brisbane", "24. Portland", "25. Oslo"];
      var citiesString = cities.join(', ');
    
      var asia = ["Tokyo", "Kyoto", "Fukuoka", "Hong Kong", "Singapore" ];
      var asiaString = asia.join(', ');
      var asiaLength = asia.length;
    
      var australia = ["Melbourne", "Sydney", "Auckland", "Brisbane" ];
      var australiaString = australia.join(', ');
      var australiaLength = australia.length;
    
      var europe = ["Vienna", "Berlin", "Munich", "Copenhagen", "Zürich", "Hamburg",
                    "Madrid", "Stockholm", "Helsinki", "Lisbon", "Barcelona", "Dusseldorf",
                    "Amsterdam", "Oslo" ];
      var europeString = europe.join(', ');
      var europeLength = europe.length;
    
      var northAmerica = ["Vancouver", "Portland"];
      var northAmericaString = northAmerica.join(', ');
      var northAmericaLength = northAmerica.length;
    
      var none = ["none listed", "0"];
    
    
      var logo = "https://i.pinimg.com/736x/0d/80/e8/0d80e89b2aa4f3ee93f0aeec01dfc60d--monocle-magazine-logo-type.jpg";
      // var vidLink = "https://vimeo.com/223486210";
      var vidLink = "https://monocle.com/film/affairs/quality-of-life-survey-top-25-cities-2017/";
    
    
    bot.hear(/Where are the world's most livable cities for 2017?/i, function(res) {
      return res.reply("According to Monocle magazine's Quality of Life Survey of 2017, the \"World's Most Liveable Cities of 2017\" are: "
          + "\n" + logo + "\n" + citiesString + "\n" + "\n" +
          "For additional information, please view the video below: " + "\n" + vidLink);
    });
    
    bot.hear(/Are there any cities from Asia?/i, function(res) {
      return res.reply("There are " + asiaLength + " cities from Asia. " + "\n" + "They are - " + asiaString);
    });
    
    bot.hear(/Are there any cities from Europe?/i, function(res) {
      return res.reply("There are " + europeLength + " cities from Europe. " + "\n" + "They are - " + europeString);
    });
    
    bot.hear(/Are there any cities from Australia?/i, function(res) {
      return res.reply("There are " + australiaLength + " cities from Australia.  " + "\n" + "They are - " + australiaString);
    });
    
    bot.hear(/Are there any cities from North America?/i, function(res) {
      return res.reply("There are " + northAmericaLength + " cities from North America. " + "\n" + "They are - " + northAmericaString);
    });
    
    bot.hear(/Are there any cities from South America?/i, function(res) {
      return res.reply("There are " + none[1] + " cities from South America. " + "\n" + "They are - " + none[0]);
    });
    
    bot.hear(/Are there any cities from Africa?/i, function(res) {
      return res.reply("There are " + none[1] + " cities from Africa. " + "\n" + "They are - " + none[0]);
    });
    
    bot.hear(/Are there any cities from Antartica?/i, function(res) {
      return res.reply("There are " + none[1] + " cities from Antartica. " + "\n" + "They are - " + none[0]);
    });
    
    
    // end - World’s Top 25 Most Liveable Cities for 2017
    
    
    // ********************************************************************************
    
    
    // #3 - "Rock, Paper, Scissors Game" start
    
    
    bot.hear(/Let's play rock, paper, scissors/i, function(res){ // RPS game starts
      return res.send("Ok, it's on! " + "\n" + "\n" +
      "Instructions: start by typing the following message: " + "\n" + "\n" +
      " \"I choose\" followed by either \"rock\", \"paper\" or \"scissors\" (without the quotes) " +
      "and I will reveal what I chose as well as declare a winner.");
    });
    
    
      bot.hear(/I choose (.*)/i, function(msg) {
        var user;
        user = msg.match[1];
    
        var computerChoice = Math.random();
          if (computerChoice < 0.34) {
          	computerChoice = "rock";
          } else if(computerChoice <= 0.67) {
          	computerChoice = "paper";
          } else {
          	computerChoice = "scissors";
          } console.log("Computer: " + computerChoice);
    
        // var choices = ["rock", "paper", "scissors"];
        // var computerChoice = function() {
        //   choices[Math.floor(Math.random() * choices.length)];
        //   return(computerChoice);
        // }
    
        var tieMsg = "The result is a tie!";
        var rockMsg = "Result: Rock wins!";
        var paperMsg = "Result: Paper wins!";
        var scissorsMsg = "Result: Scissors wins!";
        var errorMsg = "Invalid!!! Please select either rock, paper or scissors";
    
      var game = function(choice1, choice2) {
    
          if (choice1 === choice2) {
              return(tieMsg);
          }
          if (choice1 === "rock") {
              if(choice2 ==="scissors") {
                  return(rockMsg);
              } else {
                  return(paperMsg);
              }
          }
          if (choice1 === "paper") {
              if(choice2 ==="rock") {
                  return(paperMsg);
              } else {
                  return(scissorsMsg);
              }
          }
          if (choice1 === "scissors") {
              if (choice2 === "rock") {
                  return(rockMsg);
              } else {
                  return(scissorsMsg);
              }
          }
          if (choice1 !== "rock" || "paper" || "scissors") {
            return(errorMsg);
          }
      };
    
      return msg.send("Data chose " + computerChoice + "\n" + "\n" + game(user, computerChoice));
    
      }); // end - Rock, Paper, Scissors Game
    
    
    }; // end - module.exports funciton
    
    
    

    external by DianeCho modified Saturday at 4:19:16 PM  2  0  1  0

    Scopes in JS

    Scopes in JS: Explaining Local and Global Scope
    What is scope? Your explanation should include the idea of global vs. local scope.
      Scope: Two types- local or global. It determines the accessibility of variables, objects, and functions from different parts of the code.
         Local Scope: Variables declared within the function. It can only be accessed within that function
         Global Scope: A variable declared outside a function. All scripts and functions can access it. 
    
    Why are global variables avoided?
      Because it can overwrite window variables or functions
      
    Explain JavaScript's strict mode
      When the value is undefined
    
    What are side effects, and what is a pure function?
      Pure function:
        Given the same input, will always return the same output.
        Produces no side effects.
      Side effects:
        Is any effect other than that return value
    
    

    external by Github modified Wednesday at 7:21:17 PM  2  0  1  0

    Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-v0.4.18+commit.9cf6e910.js&optimize=undefined&gist=

    Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-v0.4.18+commit.9cf6e910.js&optimize=undefined&gist=: SimpleStorage.sol
    pragma solidity ^0.4.11;
     
     contract SimpleStorage {
         uint public valor;
         
         function SimpleStorage(uint novoValor) {
             valor = novoValor;
         }
         
         function incrementa()public{
             valor += 1;
         }
     }
    
    
    • Public Snippets
    • Channels Snippets