10BC0 Fix getRed/setRed example to use HSL→RGB conversion by ShilpaG813 · Pull Request #42086 · mdn/content · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@ShilpaG813
Copy link
Contributor

Fixes #42059

Description

Updates the Color class example so that getRed() and setRed() correctly operate on the red
channel after the internal representation was changed from RGB to HSL. Previously, the example
incorrectly accessed values[0], which is the hue component in HSL.

Motivation

The documentation states that the internal storage is changed to HSL using rgbToHSL().
Therefore, getRed() and setRed() must convert HSL → RGB when reading or modifying the red channel.
This PR aligns the example with the encapsulation explanation and corrects the logic.

Additional details

  • getRed() now returns the red component via hslToRGB(this.values)[0]
  • setRed() now converts HSL → RGB, updates the red value, and converts back to HSL
  • Example output updated to show 255

@ShilpaG813 ShilpaG813 requested a review from a team as a code owner November 24, 2025 14:22
@ShilpaG813 ShilpaG813 requested review from Josh-Cena and removed request for a team November 24, 2025 14:22
@github-actions github-actions bot added Content:JS JavaScript docs size/s [PR only] 6-50 LoC changed labels Nov 24, 2025
@github-actions
Copy link
Contributor
github-actions bot commented Nov 24, 2025

Preview URLs

(comment last updated: 2025-11-24 16:51:22)

Copy link
Member
@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you

@Josh-Cena Josh-Cena changed the title Fix getRed/setRed example to use HSL→RGB conversion (Issue #42059) Fix getRed/setRed example to use HSL→RGB conversion Nov 24, 2025
@Josh-Cena Josh-Cena merged commit b19d25f into mdn:main Nov 24, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:JS JavaScript docs size/s [PR only] 6-50 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug in example of use of getter/setter methods in JavaScript "using classes" guide

2 participants

0