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">
- //--------------------------------------------------------------------------------
- //Name: Kat Powell
- //--------------------------------------------------------------------------------
- //--------------------------------------------------------------------------------
- //Exercise: Primitives, Objects, and Type Checking
- //--------------------------------------------------------------------------------
- //Primitives:
- // Strings: 'Hello'
- // Numbers: 9
- // Boolean Values (True, False)
- // Null (The absense of a value)
- //Objects:
- // In real life, a car is an object. In Javascript, the car (object) has properties (weight and color) and //methods (start and stop);
- //Type checking:
- // Operator that returns a string indicating the type of the unevaluated operand-
- //Undefined, Null, Boolean, Number, String, Symbol (ES6), Function Object, Any other object
- //var a = 'Hello';
- //typeof a
- //output: string
- //--------------------------------------------------------------------------------
- //Exercise: Debugging and Documentation
- //--------------------------------------------------------------------------------
- // Console.log - used to lof code to the console
- // Comments - used to communicate intentio to other devs
- // Inline comments are with the // symbol and block-level is with the /* .. */ method
- //--------------------------------------------------------------------------------
- //Exercise: Math Operations
- //--------------------------------------------------------------------------------
- // Basic Math:
- var x = 1;
- x += 1;
- console.log(x);
- x -= 1;
- console.log(x);
- x *= 1;
- console.log(x);
- x % 1;
- console.log(x);
- x /= 1;
- console.log(x);
- //--------------------------------------------------------------------------------
- //Exercise: String Operations
- //--------------------------------------------------------------------------------
- var foo = ['Mountain Climbing', 'Hiking', 'Rowing', 'Bird Watching'];
- console.log(foo);
- console.log(outdoorAdventures.slice(2));
- console.log(outdoorAdventures.toUpperCase(0));
- console.log(outdoorAdventures.charAt());
- //--------------------------------------------------------------------------------
- //Exercise: Control Flow and Loops
- //--------------------------------------------------------------------------------
- // If/ Else/ Else If
- for (i = 1; i <= 100; i++){
- if (i % 3 === 0 && i % 5 === 0){
- console.log("Fizzbuzz");
- } else if( i % 3 === 0 ) {
- console.log("Fizz");
- } else if (i % 5 === 0){
- console.log("Buzz");
- } else {
- console.log(i);
- }
- }
- //--------------------------------------------------------------------------------
- //Exercise: Recursive Function
- //--------------------------------------------------------------------------------
- //Recursion is a technique for iterating over an operation by having a function call itself repeatedly //until is arrives at a result. Most loops can be rewritten in a recursive style, and in some
- //functional languages, this approach to looping is the default.
- // Example 1:
- let total = 150;
- for (let i = 1; i <=150 ; i++) { // use the for loop to set up the parameters
- total += i;
- }
- console.log(total);
- //Example 2:
- function factorial(n) {
- if (n === 0) {
- return 1;
- }
- //Recursion starts here:
- return n * factorial (n-1);
- }
- factorial(10);
- // output: 3628800
- //--------------------------------------------------------------------------------
- //Exercise: Constructors
- //--------------------------------------------------------------------------------
- class Surgeon {
- constructor(name, department) {
- // method on a class that runs everytime the clas is called- it's purpose is to CONSTRUCT the class when //you instantiate.
- class HospitalEmployee {
- constructor(name) {
- this._name = name; // The this keyword acts like a pronoun does in an English sentence
- this._remainingVacationDays = 20;
- }
- get name() {
- return this._name;
- }
- get remainingVacationDays() {
- return this._remainingVacationDays;
- }
- takeVacationDays(daysOff) {
- this._remainingVacationDays -= daysOff;
- }
- static generatePassword() {
- return Math.floor(Math.random()*10000);
- }
- }
- class Nurse extends HospitalEmployee {
- constructor(name, certifications) {
- super(name);
- this._certifications = certifications;
- }
- get certifications() {
- return this._certifications;
- }
- addCertification(newCertification) {
- this.certifications.push(newCertification);
- }
- }
- const nurseOlynyk = new Nurse('Olynyk', ['Trauma','Pediatrics']);
- nurseOlynyk.takeVacationDays(5);
- console.log(nurseOlynyk.remainingVacationDays);
- nurseOlynyk.addCertification('Genetics');
- console.log(nurseOlynyk.certifications);
- //--------------------------------------------------------------------------------
- //Exercise: Arrays
- //--------------------------------------------------------------------------------
- var cars = [
- 'Saab',
- 'Volvo',
- 'BMW'
- ];
- cars.push('honda'); // pushes honda into the end of the array
- console.log(cars[3]); // calls an element from the array
- console.log(cars.length); // logs the length of the array
- //--------------------------------------------------------------------------------
- //Exercise: Functions
- //--------------------------------------------------------------------------------
- // A Function is a block of code designed to perform a task.
- // Function Declarations - a function that is bound to an identifier or name.
- const isGreaterThan = (numberOne, numberTwo)=> {
- if (numberOne > numberTwo){
- return true;
- } else {
- return false;
- }
- }
- console.log(isGreaterThan(16, 20));
- //Function Expressions - similar to function declaration, but the identifier can be omitted, which
- //creates an anonymous function. Function expressions are also often stored in a variable.
- const square = function (number) {
- return number * number;
- };
- console.log(square(5));
- // Output: 25.
- //Arrow Functions - Refactored function syntax
- const isGreaterThan = (numberOne, numberTwo)=> {
- if (numberOne > numberTwo){
- return true;
- } else {
- return false;
- }
- }
- console.log(isGreaterThan(16, 20));
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">//--------------------------------------------------------------------------------
- //Name: Kat Powell
- //--------------------------------------------------------------------------------
- //--------------------------------------------------------------------------------
- //Exercise: Primitives, Objects, and Type Checking
- //--------------------------------------------------------------------------------
- //Primitives:
- // Strings: 'Hello'
- // Numbers: 9
- // Boolean Values (True, False)
- // Null (The absense of a value)
- //Objects:
- // In real life, a car is an object. In Javascript, the car (object) has properties (weight and color) and //methods (start and stop);
- //Type checking:
- // Operator that returns a string indicating the type of the unevaluated operand-
- //Undefined, Null, Boolean, Number, String, Symbol (ES6), Function Object, Any other object
- //var a = 'Hello';
- //typeof a
- //output: string
- //--------------------------------------------------------------------------------
- //Exercise: Debugging and Documentation
- //--------------------------------------------------------------------------------
- // Console.log - used to lof code to the console
- // Comments - used to communicate intentio to other devs
- // Inline comments are with the // symbol and block-level is with the /* .. */ method
- //--------------------------------------------------------------------------------
- //Exercise: Math Operations
- //--------------------------------------------------------------------------------
- // Basic Math:
- var x = 1;
- x += 1;
- console.log(x);
- x -= 1;
- console.log(x);
- x *= 1;
- console.log(x);
- x % 1;
- console.log(x);
- x /= 1;
- console.log(x);
- //--------------------------------------------------------------------------------
- //Exercise: String Operations
- //--------------------------------------------------------------------------------
- var foo = ['Mountain Climbing', 'Hiking', 'Rowing', 'Bird Watching'];
- console.log(foo);
- console.log(outdoorAdventures.slice(2));
- console.log(outdoorAdventures.toUpperCase(0));
- console.log(outdoorAdventures.charAt());
- //--------------------------------------------------------------------------------
- //Exercise: Control Flow and Loops
- //--------------------------------------------------------------------------------
- // If/ Else/ Else If
- for (i = 1; i <= 100; i++){
- if (i % 3 === 0 && i % 5 === 0){
- console.log("Fizzbuzz");
- } else if( i % 3 === 0 ) {
- console.log("Fizz");
- } else if (i % 5 === 0){
- console.log("Buzz");
- } else {
- console.log(i);
- }
- }
- //--------------------------------------------------------------------------------
- //Exercise: Recursive Function
- //--------------------------------------------------------------------------------
- //Recursion is a technique for iterating over an operation by having a function call itself repeatedly //until is arrives at a result. Most loops can be rewritten in a recursive style, and in some
- //functional languages, this approach to looping is the default.
- // Example 1:
- let total = 150;
- for (let i = 1; i <=150 ; i++) { // use the for loop to set up the parameters
- total += i;
- }
- console.log(total);
- //Example 2:
- function factorial(n) {
- if (n === 0) {
- return 1;
- }
- //Recursion starts here:
- return n * factorial (n-1);
- }
- factorial(10);
- // output: 3628800
- //--------------------------------------------------------------------------------
- //Exercise: Constructors
- //--------------------------------------------------------------------------------
- class Surgeon {
- constructor(name, department) {
- // method on a class that runs everytime the clas is called- it's purpose is to CONSTRUCT the class when //you instantiate.
- class HospitalEmployee {
- constructor(name) {
- this._name = name; // The this keyword acts like a pronoun does in an English sentence
- this._remainingVacationDays = 20;
- }
- get name() {
- return this._name;
- }
- get remainingVacationDays() {
- return this._remainingVacationDays;
- }
- takeVacationDays(daysOff) {
- this._remainingVacationDays -= daysOff;
- }
- static generatePassword() {
- return Math.floor(Math.random()*10000);
- }
- }
- class Nurse extends HospitalEmployee {
- constructor(name, certifications) {
- super(name);
- this._certifications = certifications;
- }
- get certifications() {
- return this._certifications;
- }
- addCertification(newCertification) {
- this.certifications.push(newCertification);
- }
- }
- const nurseOlynyk = new Nurse('Olynyk', ['Trauma','Pediatrics']);
- nurseOlynyk.takeVacationDays(5);
- console.log(nurseOlynyk.remainingVacationDays);
- nurseOlynyk.addCertification('Genetics');
- console.log(nurseOlynyk.certifications);
- //--------------------------------------------------------------------------------
- //Exercise: Arrays
- //--------------------------------------------------------------------------------
- var cars = [
- 'Saab',
- 'Volvo',
- 'BMW'
- ];
- cars.push('honda'); // pushes honda into the end of the array
- console.log(cars[3]); // calls an element from the array
- console.log(cars.length); // logs the length of the array
- //--------------------------------------------------------------------------------
- //Exercise: Functions
- //--------------------------------------------------------------------------------
- // A Function is a block of code designed to perform a task.
- // Function Declarations - a function that is bound to an identifier or name.
- const isGreaterThan = (numberOne, numberTwo)=> {
- if (numberOne > numberTwo){
- return true;
- } else {
- return false;
- }
- }
- console.log(isGreaterThan(16, 20));
- //Function Expressions - similar to function declaration, but the identifier can be omitted, which
- //creates an anonymous function. Function expressions are also often stored in a variable.
- const square = function (number) {
- return number * number;
- };
- console.log(square(5));
- // Output: 25.
- //Arrow Functions - Refactored function syntax
- const isGreaterThan = (numberOne, numberTwo)=> {
- if (numberOne > numberTwo){
- return true;
- } else {
- return false;
- }
- }
- console.log(isGreaterThan(16, 20));
- </script></body>
- </html>
Add Comment
Please, Sign In to add comment