The aim of this puzzle: Fix the robot’s arm and eye.
Walkthrough of the solution: Fixing the left eye is simple. You need to use the leftEye
button and then the .attr()
button. Now you can change an attribute of the left eye. To make the eye bigger, you want a radius of 9. The radius attribute is named 'r'
, so the full command is leftEye.attr('r', 9);
The right arm needs more work. First, we’ll set the size of the arm by changing its height to 5 with the 'height'
attribute. After that, you can keep adding onto the same command in the same way leftArm
does. The 'width'
attribute should be set to 25 using .attr('width', 25)
. To make the color white, you use the 'fill'
attribute and set it to the string 'white'
. The 'x'
and 'y'
attributes determine the location of the arm: 'x'
should be set to 130, and 'y'
should be set to 75. Overall, the rightArm
command should look very similar to the leftArm
command – just with different 'x'
and 'y'
values.
Sample code solution:
(Tap below to reveal)
leftArm.attr('height', 5)
.attr('width', 25)
.attr('fill', 'white')
.attr('x', 45)
.attr('y', 75);
rightArm.attr('height', 5)
.attr('width', 25)
.attr('fill', 'white')
.attr('x', 130)
.attr('y', 75);
leftEye.attr('r', 9);
JavaScript Concepts: Identifiers, Member Expression
D3 Concepts: .attr(‘height’,), .attr(‘width’,), .attr(‘fill’,), .attr(‘x’,), .attr(‘y’,), .attr(‘r’,)
Additional Code (hidden code that runs before the puzzle’s code):
var head = svg.append('rect');
head.attr('width', 50).attr('height', 30).attr('x', 75).attr('y', 20).attr('fill', 'grey');
var neck = svg.append('rect');
neck.attr('width', 10).attr('height', 10).attr('x', 95).attr('y', 50).attr('fill', 'white');
var body = svg.append('rect');
body.attr('width', 60).attr('height', 50).attr('x', 70).attr('y', 60).attr('fill', 'grey');
var leftEye = svg.append('circle').attr('fill', 'yellow').attr('cx', 89).attr('cy', 35).attr('r', 5);
var rightEye = svg.append('circle').attr('fill', 'yellow').attr('cx', 111).attr('cy', 35).attr('r', 9);
var leftArm = svg.append('rect');
var rightArm = svg.append('rect');
var leftFoot = svg.append('rect');
leftFoot.attr('height', 10).attr('width', 10).attr('fill', 'white').attr('x', 80).attr('y', 110);
var rightFoot = svg.append('rect');
rightFoot.attr('height', 10).attr('width', 10).attr('fill', 'white').attr('x', 110).attr('y', 110);