×

2.3.9 Nested Views Codehs Now

Many CodeHS graphics libraries do not automatically offset child coordinates. If you set avatar.setPosition(10, 10) and the parent is at (100, 100), the avatar might appear at (10, 10) on the screen (overlapping the parent's corner) or at (110, 110).

Fix: Check the documentation for your specific version. If relative coordinates are not supported, manually offset: 2.3.9 nested views codehs

var parentX = 100, parentY = 100;
avatar.setPosition(parentX + 10, parentY + 10);

When solving 2.3.9, keep these three rules in mind to avoid common errors: Many CodeHS graphics libraries do not automatically offset

The parent is a container. We will use a Rectangle or a specialized Panel. When solving 2

// Parent View: The profile card container
var profileCard = new Rectangle(200, 250);
profileCard.setPosition(100, 100); // Position on the main screen
profileCard.setColor("lightgray");
profileCard.setBorderWidth(2);
profileCard.setBorderColor("black");

Assume we are using the CodeHS JavaScript Graphics library.

// Import the necessary modules (if required in your version)
var main = new Tab(); // Main screen tab