Git Product home page Git Product logo

8-0-react-forms-lab's Introduction

React Forms Lab

Using React, build a form that will dynamically take in text and perform a mathematical operation on it.

Example of the clicker game.


Lab Setup

Getting started

  1. Fork and clone this repository.

  2. Navigate to the cloned repository's directory on your command line. Then, run the following command:

    npm install
    

    This will install the libraries needed to run the tests.

  3. Open up the repository in VSCode. Follow the instructions below to complete the Lab.

Tests

To run the tests, you can run the following command from the command line. You will need to be in the root directory of your local directory.

npm test

This will open the Cypress testing window, where you can click to run an individual suite of tests or all of the tests at once.

Testing Tips

Keep the following in mind for this lab as you run the tests.

  1. While running your tests, you must have a server up and running in another terminal. This means you will have both a terminal window running the actual React application and a terminal window running the tests.

  2. When creating a component, make sure to create and import it with the same name as the file name. For example, the component created and exported inside of the Post.js file should be Post. The tests look for these specific names.

  3. While the cypress-watch-and-reload package has been installed in this project, sometimes the React application will take longer to reload than the tests. If you feel as though a test should be passing that isn't, try pressing the re-run button in the Cypress tests before asking for help.

Instructions

Build a React app containing:

  • An input where the user can enter comma-separated number values in an array.
  • A select input to choose between calculating the sum, the average, and the mode -- the most frequently occurring number.
  • A "Calculate" button that, when pressed, puts the result of the selected operation on the input numbers on the screen.
    • If the numbers are invalid for some reason, display the exact message Invalid input., keeping the punctuation.

You should leave the component structure as is.

Examples

For example, if the text input contains 1,3,3,7 and the select is set to sum, clicking the button should print 14 to the screen. Switching the select to mode and clicking the button again would replace that with 3.

input operation result
1 average 1
1 mode 1
1 sum 1
1,3,5 average 3
1,3,5 mode 1
1,3,5 sum 9
* Invalid input.
apple * Invalid input.
1,pie * Invalid input.

Bonus

There are additional challenges in place should you want to use them.

  • If the input is valid, clear the input boxes after the "Calculate" button is clicked.
  • If the input is invalid, do not clear the input boxes after the "Calculate" button is clicked.
  • Add a class of "error" to both the input and select elements if the input is invalid.
    • If the input is then changed so that it is valid, remove those classes the next time the "Calculate" button is clicked.

Example of the the bonus error styling.

8-0-react-forms-lab's People

Contributors

aishackleemoff avatar bwreid 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.