Git Product home page Git Product logo

robot-simulator-v2's Introduction

Robot Simulator v3

This DQ Lovingly Stolen From The Masta Balasta

Welcome to Robot Simulator! We're building a digital space for a robot to move around in! We've got the robot and the robot's got the moves, but it's up to you figure out how to get the user to control how it moves!

Objectives

  • Gain a better understanding of DOM management
  • Learn how to manage data on the frontend
  • Use event listeners in new and interesting ways

Task

Open up the index.html file in your browser and please read all of the instructions before beginning.

You will be coding only within the index.js file - the movement.js file provides you with the code to move the robot. You can peek at this code if you're curious, but it is not advised that you edit it.

We've got a robot displayed in a grid. The robot is capable of moving along this grid using a function called move which has been provided for you. When called with a string left, down, right, or up, the move function will move the robot in that direction. Try it out in your console!

Example:

move("right") // moves robot to the right

Store the commands

Your task is to add functionality to the page such that when a user presses the arrow keys, that direction (i.e. left, down, right, or up) is added to a list of directions on the right side of the robot's grid. We've already provided you with a <ul> element with an id set to moves-container - you just have to add li elements to it containing the direction that was inputted.

Example:

<ul id="moves-container">
  <li>Down</li>
  <li>Right</li>
  <li>Down</li>
  <li>Right</li>
</ul>

Move the robot

The robot does NOT move until the user presses the Move! button. When this button is clicked, the direction at the top should be removed from the moves container <ul> and the robot should move in that direction.

Note: If the robot hits a wall, it will not move and you will instead see a alert saying "Clang! Hit a wall"

Delete a move

When a user clicks on a move <li>, delete that move from the moves container <ul>.

Note: think about using Event Delegation vs attaching individual event listeners to each new list item. What edge cases do you need to handle?

Bonus!

When the "Move!" button is clicked, the robot automatically moves according the the list of directions every half second. The directions should disappear from your list of directions as the robot moves. You may want to look into setInterval or setTimeout.

robot-simulator-v2's People

Contributors

sbal13 avatar ihollander 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.