MCPcopy Create free account
hub / github.com/LinkedInLearning/javascript-essential-training-2832077 / Backpack

Class Backpack

04_02/Backpack.js:1–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Backpack {
2 constructor(
3 name,
4 volume,
5 color,
6 pocketNum,
7 strapLengthL,
8 strapLengthR,
9 lidOpen,
10 dateAcquired
11 ) {
12 this.name = name;
13 this.volume = volume;
14 this.color = color;
15 this.pocketNum = pocketNum;
16 this.strapLength = {
17 left: strapLengthL,
18 right: strapLengthR,
19 };
20 this.lidOpen = lidOpen;
21 this.dateAcquired = dateAcquired;
22 }
23 toggleLid(lidStatus) {
24 this.lidOpen = lidStatus;
25 }
26 newStrapLength(lengthLeft, lengthRight) {
27 this.strapLength.left = lengthLeft;
28 this.strapLength.right = lengthRight;
29 }
30 backpackAge() {
31 let now = new Date();
32 let acquired = new Date(this.dateAcquired);
33 let elapsed = now - acquired; // elapsed time in milliseconds
34 let daysSinceAcquired = Math.floor(elapsed / (1000 * 3600 * 24));
35 return daysSinceAcquired;
36 }
37}
38
39export default Backpack;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected