Complete the code to set the opacity of a layer to 50%.
layer.opacity = [1]Opacity in Figma is set as a decimal between 0 and 1, where 0.5 means 50% opacity.
Complete the code to reduce the opacity of a selected object by 20%.
selected.opacity = selected.opacity - [1]To reduce opacity by 20%, subtract 0.2 from the current opacity value.
Fix the error in the code to set opacity to 75%.
frame.opacity = [1]Opacity must be a decimal between 0 and 1, so 75% is 0.75.
Fill both blanks to set the opacity of a rectangle to 30% and then increase it by 10%.
rectangle.opacity = [1] rectangle.opacity = rectangle.opacity + [2]
30% opacity is 0.3. Increasing by 10% means adding 0.1.
Fill all three blanks to create a function that sets opacity to a given percent, ensuring the value stays between 0 and 1.
function setOpacity(obj, percent) {
let value = percent / [1];
obj.opacity = Math.min(Math.max(value, [2]), [3]);
}Divide percent by 100 to get decimal. Clamp between 0 and 1 using Math.min and Math.max.
