Skip to content

Commit b19d25f

Browse files
Fix getRed/setRed example to use HSL→RGB conversion (#42086)
* fix: correct getRed()/setRed() example using HSL→RGB conversion (#42059) * Fix usage --------- Co-authored-by: Joshua Chen <[email protected]>
1 parent e888d05 commit b19d25f

File tree

1 file changed

+4
-2
lines changed
  • files/en-us/web/javascript/guide/using_classes

1 file changed

+4
-2
lines changed

files/en-us/web/javascript/guide/using_classes/index.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,12 @@ class Color {
314314
this.values = rgbToHSL([r, g, b]);
315315
}
316316
getRed() {
317-
return this.values[0];
317+
return hslToRGB(this.values)[0];
318318
}
319319
setRed(value) {
320-
this.values[0] = value;
320+
const rgb = hslToRGB(this.values);
321+
rgb[0] = value;
322+
this.values = rgbToHSL(rgb);
321323
}
322324
}
323325

0 commit comments

Comments
 (0)