-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuilding-blocks.js
More file actions
67 lines (44 loc) · 1.43 KB
/
building-blocks.js
File metadata and controls
67 lines (44 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//7 Kyu
//Building blocks
//Fundamentals, OOP
// Write a class Block that creates a block (Duh..)
// Requirements
// The constructor should take an array as an argument, this will contain 3 integers of the form [width, length, height] from which the Block should be created.
// Define these methods:
// `getWidth()` return the width of the `Block`
// `getLength()` return the length of the `Block`
// `getHeight()` return the height of the `Block`
// `getVolume()` return the volume of the `Block`
// `getSurfaceArea()` return the surface area of the `Block`
// Examples
// let b = new Block([2,4,6]) -> creates a `Block` object with a width of `2` a length of `4` and a height of `6`
// b.getWidth() // -> 2
// b.getLength() // -> 4
// b.getHeight() // -> 6
// b.getVolume() // -> 48
// b.getSurfaceArea() // -> 88
// Note: no error checking is needed
// Any feedback would be much appreciated
//Solution
class Block{
constructor(arr){
this.width = arr[0];
this.length = arr[1];
this.height = arr[2];
}
getWidth(){
return this.width
}
getLength(){
return this.length
}
getHeight(){
return this.height
}
getVolume(){
return this.getWidth() * this.getLength() * this.getHeight()
}
getSurfaceArea(){
return (2*(this.getWidth() * this.getLength())) + (2*(this.getWidth()* this.getHeight())) + (2*(this.getLength() * this.getHeight()))
}
}