Coding Cups
I am just learning...

  • Use + to look for one or more characters
  • Use * to look for zero or more characters.
  • You can search the end of strings using the $ character at the end of the regex.
    let theEnding = "This is a never ending story";
    let storyRegex = /story$/;
    storyRegex.test(theEnding);
    // Returns true
    let noEnding = "Sometimes a story will have to end";
    storyRegex.test(noEnding);
    // Returns false
    

Terminal Commands


a == b ? console.log("Match!") : console.log("No match!");

if condition a equals b is true, then do one thing, else do something else. The Ternary Operator makes this into a single line of code for us where it says the condition, question mark, the true statement, colon, the false statement. So, if a equals b is true, then console log match. Otherwise, console log no match.


With ECMAScript 2015, or ES6, we have two new types of variables you can use in addition to var. They are const and let.


AJAX uses JavaScript to make changes to the current document through something called the DOM. This is the Document Object Model, and its job is to keep track of the structure of our HTML document. When you work with AJAX it’s usually because you want to change something in your page after it has loaded. The easiest way to make a change in the DOM is through a JavaScript method called getElementByID.


Although AJAX was designed to work with files in the XML format, it will read the contents of any text file. So the data can really be in any format; the trick is to know how to parse or translate the data into objects that JavaScript can manipulate. An obvious choice is to use the file in the JSON format. JASON stands for JavaScript Object Notation, and is a way to structure data so that it can be easily converted to a JavaScript object.


Reading XML data into JavaScript is super simple. As a matter of fact, the XHR object comes with a special attribute called responseXML. It’s sort of like the responseText property, except that it converts the data into an object that you can manipulate through JavaScript.


jQuery is a framework that fixes compatibility issues that happen with JavaScript in older browsers. The library also gives you a lot of additional tools for working with the DOM and makes it easy to work with AJAX. jQuery is taking care of a lot of problems with backwards compatibility in older browsers, and it also creates and sends the XHR request.


To modify a group of elements use getElementsByTagName:


()[https://www.w3schools.com/tags/ref_eventattributes.asp]


The first step in working with AJAX is to learn about the API browsers provide for sending and retrieving information. The way you access the API is by using a XML HTTP request or XHR object.


Although usage of early versions of Internet Explorer have dropped dramatically in the last few years, it’s still important to know how to run AJAX requests that are compatible with those systems. And actually, the whole concept behind XHR requests was created by Microsoft and implemented first in a browser in IE5. To accomplish this, Microsoft used a technology called ActiveX. Because ActiveX was not available to other browsers like Safari, Firefox, and Chrome, they created a different implementation of the API using the XMLHttpRequest object.


So AJAX requests are supposed to be asynchronous by nature, which means that they should run in the background independently of other events.


To help structure our code and make common operations reusable, we create functions and objects. Functions are mini programs inside our scripts. They can be used to segment off sections of our code to make it easier to manage, or to run repeated operations, or both. Functions wrap around code blocks, which contain the actual statements to be run, and typically include some combination of variable assignments, operations, and conditions.


Arrays are objects.

  • In JavaScript, objects have properties and methods.
  • Properties are pieces of meta information about the object we can retrieve and use.
  • Methods are functions that belong to that object.

Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain exactly 4 sub-arrays.


jQuery(document).ready(function($) {
  $('[data-toggle="ajaxModal"]').on('click',
              function(e) {
                $('#ajaxModal').remove();
                e.preventDefault();
                var $this = $(this)
                  , $remote = $this.data('remote') || $this.attr('href')
                  , $modal = $('<div class="modal" id="ajaxModal"><div class="modal-body"></div></div>');
                $('body').append($modal);
                $modal.modal({backdrop: 'static', keyboard: false});
                $modal.load($remote);
              }
            );
   });

http://stackoverflow.com/questions/19663555/bootstrap-3-how-to-load-content-in-modal-body-via-ajax


A handy soluition for adding modal popups to your website.


returns an object where the keys are the duplicate entries and the values are an array with their indices