100 JS Functions

Beginner

1. CurrentYear

2. SimpleCounter

3. DoubleNumber

4. CreateColor

5. DynamicGrid

6. DynamicPictureSize

7. RandomButton

8. TabbedNavigation

9. MathOperator

10. GuessTheNumber

11. BetweenDates

12. Reactions

13. FeedTheBunny

14. Countdown

15. ClickFast

16. SkillsForJobs

17. UsersTabel

18. TodoList

19. UserSearch

20. SpendingInfo

9.MathOperator

Write a React component named MathOperator that renders: two number inputs, a <select> dropdown between them labeled Choose operator and a Calculate button.

The <select> should have four possible values:

  • +
  • -
  • *
  • /

When the Calculate button is clicked, perform the selected operation between the two inputs and show the result in a paragraph like so: Result is: {number}

Example:

  • Input 1: 21
  • Input 2: 42
  • Operator: /

Result is: 0.5

If the calculation cannot be performed, render a paragraph with an appropriate message. For example:

  • Enter both numbers
  • Cannot divide by zero

Example 1

Input

No input props

Demo

Open demo in new window

You'll see test results here!