Coder Social home page Coder Social logo

hs-js-cartoon-collections's Introduction

Objectives

You're going to get familiar with iterating through arrays in Javascript.

Instructions

There are four functions to complete in this lab:

  1. Dwarf Roll Call
  2. Summon Captain Planet
  3. Long Planeteer Calls
  4. Find the Cheese

Function 1 - Dwarf Roll Call

dwarves

This function should accept an array of dwarf names, for instance:

["Doc", "Dopey", "Bashful", "Grumpy"]

It should then return a string with the numbered dwarves. The string should look like this:

"1. Doc 2. Dopey 3. Bashful 4. Grumpy "

Function 2 - Summon Captain Planet

captain-planet

This function should accept an array of planeteer calls, like this:

planeteerCalls = ["earth", "wind", "fire", "water", "heart"]

It should then convert each element to uppercase and add an exclamation point at the end. The return value of this method should be an array, in this example:

summonCaptainPlanet(planeteerCalls)
#=> ["EARTH!", "WIND!", "FIRE!", "WATER!", "HEART!"]

Once the test for this method is passing, move on to the next method, long planeteer calls.

Function 3 - Long Planeteer Calls

The longPlaneteerCalls method should accept an array of calls. The function should tell us if any of the calls are longer than four characters. For example:

shortWords = ["wind", "fire"]
longPlaneteerCalls(short_words)
#=> false

assortedWords = ["earth", "wind", "heart", "fire"]
longPlaneteerCalls(assorted_words)
#=> true

Notice the return value of this method is either false or true, depending on the array it was given as an argument.

Once the test for this method is passing, move on to the last function.

Method 4 - Find the Cheese

dancing-mice

The "findTheCheese" function should accept an array of strings. It should then look through these strings and return the first string that is a type of cheese. The types of cheese that appear are cheddar, gouda, and camembert.

For example:

snacks = ["crackers", "gouda", "thyme"]
findTheCheese(snacks)
#=> "gouda"

soup = ["tomato soup", "cheddar", "oyster crackers", "gouda"]
findTheCheese(soup)
#=> "cheddar"

If, sadly, a list of ingredients does not include cheese, return "no cheese!":

ingredients = ["garlic", "rosemary", "bread"]
findTheCheese(ingredients)
#=> null

You can assume that all strings will be lower-case.

View Objectives on Learn.co and start learning to code for free.

hs-js-cartoon-collections's People

Contributors

aspenjames avatar aviflombaum avatar dfenjves avatar ipc103 avatar jmburges avatar sgharms avatar timothylevi avatar victhevenot avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hs-js-cartoon-collections's Issues

ruby cartoon lab

I just realized that they gave me the cartoon lab in Javascript and I wrote all the answers in Ruby which is what I had on the other labs. Is there a way that I can switch my lab to Ruby ?

node-inspector dependency causes `npm install` to fail

When attempting to run npm install, the install will fail due to an error with the node-inspector package:

// ♥ npm install

> [email protected] preinstall /home/cassaram09/hs-js-cartoon-collections-js-cartoon-collections-000/node_modules/v8-debug
> node -e 'process.exit(0)'
> [email protected] install /home/omgitsgod/hs-js-cartoon-collections-js-cartoon-collections-000/node_modules/v8-debug
> node-pre-gyp install --fallback-to-build

node-pre-gyp ERR! Tried to download(404): https://node-inspector.s3.amazonaws.com/debug/v0.7.7/node-v57-linux-x64.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for [email protected] and [email protected] (node-v57 ABI, glibc) (falling back to source compile with node-gyp)
make: Entering directory '/home/omgitsgod/hs-js-cartoon-collections-js-cartoon-collections-000/node_modules/v8-debug/build'
  CXX(target) Release/obj.target/debug/src/debug.o

There's a much longer error message but this seems to be the important part. The issue documented in this thread indicates that this version of node-inspector v8-debug is only compatible with v6 of node.

This dependency seems to be used for something related to the bin/debug-ide file but not sure what. Removing the node-inspector dependency removes the errors and allows the student to continue working on the lab.

Test is missing an expectation

In the JS Cartoon Collections lab, the "summon Captain Planet" test is missing an expectation on line 20. The description of the "summon Captain Planet" test requires that the user capitalize each element in the planeteerCalls array, and then add an exclamation point to the end of that element. However, the expectation listed on line 20 only lists that the item should contain an exclamation point. It does not mention that the item should be capitalized as well. As a result, the "summon Captain Planet" test passes when the user adds an exclamation point to the end of each item, but the test only passes when the items are lowercase. The test fails when the items are uppercase.

JS Cartoon Collections Lab "summon Captain Planet" test, Line 20:
https://github.com/learn-co-curriculum/hs-js-cartoon-collections/blob/master/test/index-test.js#L20

Spec for longPlaneteerCalls causes false positive

Specs for longPlaneteerCalls passes with improper solution

The spec

describe("longPlaneteerCalls", function() {
      it("returns true if any calls are longer than 4 characters", function() {
        var longCalls = ["earth", "wind", "fire", "water", "heart"];
        expect(longPlaneteerCalls(longCalls)).toBe(true);
      });

      it("returns false if no calls are longer than 4 characters", function() {
        var shortCalls = ["wind", "fire"];
        expect(longPlaneteerCalls(shortCalls)).toBe(false);
      });
});

False Positive "Solution"

Students' first intuition may lead them to experiment with .length, but without first turning to iteration. Below is one of the possible avenues they may explore, and one I witnessed a student using:

function longPlaneteerCalls(words) {
  if (words.length > 4) {
    return true;
  } else {
    return false;
  }
}

Likewise, but more succinctly:

function longPlaneteerCalls(words) {
  return words.length > 4 ? true : false
}

Both of these solutions cause the above specs to pass.

Explanation

I'm sure you can see the thought process of the student, realizing they need .length, and trying it on the first obvious target, the words parameter. Unfortunately, the way the spec is written causes this to pass the specs, since the only example that is expecting true has five elements in the array, and the only example that is expecting false has only two elements in the array.

Calling .length on the words parameter compares the length of the array argument passed in, causing these false positives.

Proposed solution

Simply removing one word from the first spec and adding three or more words of length <= 4 to the second spec will fix this error, eliminating the possibility a student can be passing spec without properly checking the length property of the individual elements of the argument array.

#Staff

'learn' command resembles run but with no save

This could just be me, but I am used to the run command saving then running (I learned in Mumps so I don't expect to be typical), so when I submitted with "learn" repeatedly with no changes in result I assumed my syntax was always wrong. Would it be more consistent for learn to be the same? Or would that not make sense at all, given that we are really submitting our saved code to an outside source and getting a reply?

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.