Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

TDD in Javascript. Really need some help

MY WORK: https://repl.it/@karlylamm1/mars-rover-starter-2

I'm working on a project to help me better learn test driven development and I cannot figure out the rover section with the following questions: My work is in the link at the top of this

Test 9 "response returned by receiveMessage includes two results if two commands are sent in the message"

Test 10 "responds correctly to status check command"

For the STATUS_CHECK command, receiveMessage(message).results includes a roverStatus object describing the current state of the rover object --- mode, generatorWatts, and position. The test should check each of these for accuracy. See the Rover Command Types table for more details. Test 11 "responds correctly to mode change command".

The test should check the completed property and rover mode for accuracy. The rover has two modes that can be passed a values to a mode change command, 'LOW_POWER' and 'NORMAL'.

1 Answer

Blake Larson
Blake Larson
13,014 Points

Hey, so do you need help finishing the Rover receiveMessage() function to test? I see that you are testing the results array on the response but it is static with two Strings. I don't know if you just haven't gotten around to that part, but it looks like the command array sent into the receiveMessage() function is meant to change the Rover object state depending on command.commandType and command.value.

This passes your test #9 dynamically but is missing a lot of edge cases. I just made it to pass the test because I'm not sure what you want results array populated with.

receiveMessage(message){
  let completed = true;
  let response={
    message: message.name,
    results: message.commands.map(command => {
      if(command.commandType === 'MODE_CHANGE' && command.value) {
        this.mode = command.value;
        return `mode changed to ${command.value}`;
      }

      if(command.commandType === 'STATUS_CHECK') {
        return `Rover position: ${this.position}, Rover mode: ${this.mode}, Rover watts: ${this.generatorWatts}`;
      }
    })
   }


  return response
}