Giter VIP home page Giter VIP logo

quizes's Introduction

#Javascript Quiz - Sept 15

##Questions

  1. Make a Person constructor with attributes: name:string, height:string, age:number, sleeping:boolean.
function Person (name, height, age, sleeping){
  this.name = name;
  this.height = height;
  this.age = age;
  this.sleeping = true;
}

  1. Add prototype methods to person: eat, sleep, and wakeUp. (The sleep and wakeUp methods should toggle sleeping to true/false, and eat should return an eating noise.)
Person.prototype.eat = function(){
  console.log("crunch... CRUNCH!");
};

Person.prototype.sleep = function(){
  this.sleeping = true;
};

Person.prototype.wakeUp = function(){
  this.sleeping = false;
};

  1. Make a Student prototype that inherits from person and has the additional attribute of studying:boolean.
function Student (studying){
  this.studying = true;
}

Student.prototype = new Person();
Student.prototype.constructor = Student;

  1. Add methods to Student called study, and stopStudy to toggle studying
Student.prototype.student = function(studying){

  this.study = function(studying){
    if (studying === false){
      this.studying = true;
    }
  };

  this.stopStudy = function(studying){
    if (studying === true){
      this.studying = false;
    }
  };
};

  1. Override the sleep method on student to only run sleep if studying is false.
Student.prototype.sleep = function(studying){
  if (studying === false){
    this.sleep = true;
  } else {
    this.sleep = false;
  }
};

quizes's People

Contributors

salamandermike avatar bridgpal avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.