Fun with ES6 Classes #4 - Cubes and Setters
Description:
Fun with ES6 Classes #4 - Cubes and Setters
Overview
In Fun with ES6 Classes #3 - Cuboids, Cubes and Getters, we learned that if we knew all the dimensions (i.e. length, width, height
) of a cuboid, we could easily work out its corresponding volume and surface area. The way we achieved this in our code was by the use of getters which automatically computed the volume and surface area of the cuboid whenever either one of length, width, height
changed. However, in the previouos exercise, one thing we could not do is define setters for surface area or volume of a cuboid because for a given volume/SA, there were an infinite number of possibilities to the dimensions of the cuboid.
However, for cubes (a special type of cuboid), since their length
, width
and height
are always the same, it is possible to figure out the side length of a cube given its surface area and/or volume. Therefore, in this Kata, you will be asked to define setters as well as getters for both the surface area and volume of a cube.
Task
Define a class Cube
whose constructor function takes exactly one parameter length
and stores the value of the argument into this.length
. You will then define both a getter and a setter for the surfaceArea
and volume
of the cube.
No initial code will be given. You are free to use whatever syntax you like to complete this Kata but it is highly recommended that you use ES6 syntax and features to complete this Kata.
Articles of Interest
Below are some articles of interest that may help you complete this Kata:
Similar Kata:
Stats:
Created | Mar 31, 2016 |
Published | Mar 31, 2016 |
Warriors Trained | 6854 |
Total Skips | 24 |
Total Code Submissions | 14195 |
Total Times Completed | 5904 |
JavaScript Completions | 5904 |
Total Stars | 32 |
% of votes with a positive feedback rating | 89% of 268 |
Total "Very Satisfied" Votes | 222 |
Total "Somewhat Satisfied" Votes | 33 |
Total "Not Satisfied" Votes | 13 |
Total Rank Assessments | 11 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 8 kyu |