JavaScript for Web Designers

  1. JavaScript in Use

    • What is JavaScript: JavaScript is very similar to Java but is different. JavaScript is the programming language of the web, and one of the most widely used programming codes in the web. JavaScript is mostly used as a front-end development program language. It creates interactivity.
    • Live examples: Looked at some examples
    • Where you don't use JavaScript: CSS and JS can both do pretty good animations, but JS can do better animations then CSS. CSS is better at styling things and JS is better at giving things animaton, switching things around, or even just removing something.
    • JavaScript's power can be dangerous: JavaScript can be dangerous, as in with security, it could hide, or not hide, the data that you send, and could even hide it from you. JavaScript can also be used to pull and display ads, and that can cause some performance issues.There are also tracking scripts that will be needed and those are pretty large so they will also cause some performance issues. To improve your site's performonce on loading, keep your JavaScript files lean, avoid using lots of scripts.
  2. Writing and Debugging

    • Your friend the text editor: Before you start typing any JS code, you should figure out what text editor you sould use. There are a bunch out there that you could chooses from, but the most common ones are Visual Studio Code/VSCode, Sublime Text, WebStorm, BBEdit/Bare Bones Edit.
    • Browsers and tools: You will also need, alongside the code editor, a web browser, preferably up to date. There is Firefox, Google Chrome, Safari, There is also Internet Explorer, and Microsft Edge.
    • Tools in action: In every browser, there is a developer tools, inspector, or whatever it is called in different browsers, that allows you to debug code, and check for errors, or even test your code to see how it works. In the developer tools, there is a console that allows you to write JavaScript in the browser as long as you dont refresh the page.
    • Getting help: Here are a couple of sites that could help you with JavaScript if you get stuck: Stack Overflow, MDN Web Docs, Can I Use? (shows the browser compatibility), MDN Web Docs (to understand the Firefox browser), Chrome Devtools, Safari developer, Microsoft Edge Developer documentation. If you still need more assistance, then go find people who work with JavaScript by atending meetings, and other things.
    • Jargon: JavaScript is aware, and has, a lot of data types: numbers, strings, booleans, objects, arrays. It also has variables and operators. Variables in JavaScript are sort of like nouns in english, and operators are like verbs. Functions can be seen as paragraphs, and they are sort of like their own data type. If a function is inside of an object it is called a method. Arguments and parameters feed data to functions. Control structures are conditional: if-else and switch staements; or loops: for and while;.
    • Jargon: The DOM: Here are a lot of methods and other things related to the DOM: getElementByID, querySelector, querySelectorAll. There are also properties, like: value, checked, className, id.
    • Vanilla JavaScript versus frameworks: Frameworks are easy to use because they are already made, but they have the drawback of not being that editable, as in they can't really be edited without messing something up. Their are also security risks too. With Vanilla JS you can write as much code as you need and less chance of extra code being their but not being used. And it can be helpful to have prior knowledge of JavaScript before you use a framework.
  3. Working with Forms

    • Working with user info: You can use Javascript to get the info that a user puts in and puts it through a function that spits out whatever the function tells it to do.
    • Text fields and select boxes: Text fields are boxes that allow users to type a couple words into them. A select box has options for the user to click on and choose what they want.
    • Radio buttons and checkboxes: Radio buttons are buttons that have options that a user can select from, but they can only select one. Checkboxes are pretty much the same, but the difference is that a user can select multiple checkboxes instead of one.
    • Changing submission with events: An event is something a user does to interact with the browser, such as clicking, typing, or even scrolling. We can use the eventListener function to listen to an event applied to the element it is tied to, such as clicking or typing.
    • Starting to validate input: You can validate form input by using some methods to collect and save the data that was put in.
    • Disabling and enabling fields: You can disable and enable form fields with the .disbaled and set it equal to true or false.
    • The basics of sanitizing user input: Just making sure that they are numbers and that the end number is formatted correctly.
    • Get and set with innerHTML: innerHTML is a function that can hold HTML and it can put that HTML into the actual document where it is specified. Be careful though, because it could replace current HTML code.
  4. A Matter of Time

    • Use JavaScript to tell time: There is a premade browser object called Date that you can call to, and it will display the curent time though for users to be able to see it, use .toTimeString.
    • Get pieces of time: There are different methods to get pieces of time, and here are a couple: .getHours, .getMinutes, .getDay, .getSeconds, .getMonth, .getYear, and so on.
    • Use timers to update the page: Added a few methods to update the page every so often.
    • Polish the clock: Make the clock look a little better.
    • Filling in gaps with Moment.js: Here are a few sites that deal with time in JavaScript: Moment.js, GitHub. Also did some updating by using Moment.js in our script.js file
  5. Consuming a Third-Party API

    • What is an API?: An API is an Application Programming Interface. The biggest challenge with an API is terminology. Usually an API comes with a document to help you navigate the API code. Bing offers a map API to use, Google has a bunch of API's available, and so does YouTube.
    • Create a map:You would need to go to Bing Maps Dev Center, and sign in or create a new account, and either way you do it, you will have to create a new Maps Dev Center account, then navigate to the Getting Started: Creating and Hosting a Map control, and follow its directions.
    • Change the center point:This site has instructions to change the center point of the map, along with other things related to it.
    • Change the type and zoom level: Here is the site to change the type, and to change the zoom levels, go to the console and type the object your map is connected to, and then .getZoom and it will tell you the zoom number.
    • Add a marker: Here is the example code to add a pushpin:
      var pin = new Microsoft.Maps.Pushpin(center, {
      	title: 'Microsoft',
      	subTitle: 'City Center',
      	text: '1'
      });
      
      map.entities.push(pin);
      
    • Add a popup to the marker: Here is some code to make a pushpin show a popup when clicked:
      function GetMap() {
      	map = new Microsoft.Maps.Map('#myMap', {});
      
      	//Create an infobox at the center of the map but don't show it.
      	infobox = new Microsoft.Maps.Infobox(map.getCenter(), {
      		visible: false
      	});
      
      	//Assign the infobox to a map instance.
      	infobox.setMap(map);
      
      	//Create a pushpin at a random location in the map bounds.
      	var randomLocation = Microsoft.Maps.TestDataGenerator.getLocations(1, map.getBounds());
      	var pin = new Microsoft.Maps.Pushpin(randomLocation);
      
      	//Store some metadata with the pushpin.
      	pin.metadata = {
      		title: 'Pin Title',
      		description: 'Pin discription'
      	};
      
      	//Add a click event handler to the pushpin.
      	Microsoft.Maps.Events.addHandler(pin, 'click', pushpinClicked);
      
      	//Add pushpin to the map.
      	map.entities.push(pin);
      }
      function pushpinClicked(e) {
      	//Make sure the infobox has metadata to display.
      	if (e.target.metadata) {
      		//Set the infobox options with the metadata of the pushpin.
      		infobox.setOptions({
      			location: e.target.getLocation(),
      			title: e.target.metadata.title,
      			description: e.target.metadata.description,
      			visible: true
      		});
      	}
      }
      
  6. Better User Experience with an API

    • Introducing Ziptastic: Ziptastic can help with "reading minds" of what your user is typing in for a shipping address or whatever. You will have to install some sort of web browser server in order for it to work correctly.
    • Fetching data from a third-party API: You can add code that will enable you to detect what is being put into the form and then grab it and take it to where it is supposed to go.
    • Better UX for the checkout page: Axios is an API that works well with form submission pages.