Giter Club home page Giter Club logo

oregano-trail's Introduction

oregano-trail

Like Oregon Trail, but different enough to avoid litigation

Create two different types of objects: a traveler and a wagon.

A traveler has a few properties: an amount of food (number), a name (string), and an isHealthy (boolean).

A wagon has a few properties as well: a passengers list (array) and a capacity (number).

The following code should work once you are finished:

x let wagon = makeWagon(5); x let traveler = makeTraveler('Henrietta'); x let traveler2 = makeTraveler('Juan');

x hunt(traveler); // maybe get more food x eat(traveler2); ? eat(traveler2); // juan is hungry x join(wagon, traveler); x join(wagon, traveler2);

console.log(quarantine(wagon)); // print true if someone is sick, false otherwise console.log(food(wagon)); // print juan's food + henrietta's food

////////////////////////

Operations

Write the following functions, which should work on either travelers or wagons. Many of these functions will be short, and some are quite similar to things we've done before (except with objects now). Think about how the objects change how the function needs to work.

Technical note: if you change an object inside of a function, the changes will affect the original object outside of the function as well. This is not true of primitive data types (strings, numbers, booleans, etc).

makeTraveler(name) Create a new traveler object with the specified name, a random amount of food, and isHealthy = true. This should be very similar to makeCar from today's notes.

makeWagon(capacity) Create a new wagon with an empty passenger list and the specified capacity. This should be very similar to makeLot from today's notes.

hunt(traveler) 50% chance to increase the traveler's food by 100 (successful hunt), and 50% to increase it by 0 (unsuccessful hunt).

eat(traveler) Consumes 20 of the traveler's food. If the traveler doesn't have 20 food, the traveler is no longer healthy.

x join(wagon, traveler) Add the traveler to the wagon if there is space. If there is not enough capacity, don't add them.

x quarantine(wagon) Return true if there is at least one unhealthy person in the wagon. Return false if not.

food(wagon) Return the total amount of food among all occupants of the wagon.

oregano-trail's People

Contributors

joshcodegood avatar

Watchers

 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.