One Paragraph of project description goes here
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
| //NOTE: Math.random() returns a floating point number from 0 up to but not including 1. | |
| //1. inclusive at the minimum, exclusive at the maximum | |
| var max = 10; | |
| var min = 1; | |
| var result = Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive | |
| /** helper function version **/ | |
| function getRandomInt(min, max) { | |
| min = Math.ceil(min); |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>JS Bin</title> | |
| </head> | |
| <body> | |
| <form action=""> | |
| <label for="name">Name:</label> |
| //if you want the old way: | |
| function sum(){ | |
| var sum =0; | |
| for(var i=0;i<arguments.length;i++){ | |
| sum += arguments[i]; | |
| } | |
| return sum; | |
| } | |
| sum(1,2); // returns 3 |
| var numbers = [4, 44, 21, 29, 12, 7]; | |
| // Method 1: using Math.max | |
| console.log( Math.max(...numbers) ); | |
| //Method 2: using reduce | |
| var max = numbers.reduce( | |
| function(previousLargestNumber, currentLargestNumber) { | |
| return (currentLargestNumber > previousLargestNumber) ? currentLargestNumber : previousLargestNumber; | |
| } |
| /*position horizontal scroll bar at center of DIV*/ | |
| // useful when for example the min-width of a scrollable container is wider than the viewport. Like in the t-shirt demo proj, I wanted the user to see the center of the shirt on load, rather than have the user need to scroll | |
| function centerHScrollBar(){ | |
| var outerContent = $('.product-view'); | |
| var innerContent = $('.pillow-contain-show'); | |
| outerContent.scrollLeft( (innerContent.width() - outerContent.width()) / 2); | |
| } |
| //the FAV part is the approach I'd like to use. I've researched a lot about this and this seems to be a great choice. see https://codeburst.io/the-only-way-to-detect-touch-with-javascript-7791a3346685 | |
| // We really just want to know if the user is using their fingers to interact with our site. | |
| // #1 basic logic | |
| window.addEventListener('touchstart', function() { | |
| //the user touched the screen | |
| }); |
| const capitalizeFirstLetter = (s) => { | |
| if (typeof s !== 'string') return '' | |
| return s.charAt(0).toUpperCase() + s.slice(1) | |
| } | |
| capitalizeFirstLetter('puyih') //'Puyih' | |
| capitalizeFirstLetter('p') //'P' | |
| capitalizeFirstLetter(0) //'' | |
| capitalizeFirstLetter({}) //'' |
| //src: https://vanillajstoolkit.com/helpers/truetypeof/ | |
| /*! | |
| * More accurately check the type of a JavaScript object | |
| * (c) 2018 Chris Ferdinandi, MIT License, https://gomakethings.com | |
| * @param {Object} obj The object | |
| * @return {String} The object type | |
| */ | |
| var trueTypeOf = function (obj) { | |
| return Object.prototype.toString.call(obj).slice(8, -1).toLowerCase(); |
| <!doctype html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Library</title> | |
| </head> | |
| <body> | |
| <h1 id="test">[greeting]</h1> | |
| <script src="https://code.jquery.com/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" | |
| crossorigin="anonymous"></script> |