Random Rotation of an Image

setStyle(“image1”,“transform:rotate(180deg);”);
This will rotate the image 180 degrees, but what if I wanted to have the image rotate a random number of degrees each time? Is there an easy way to do that without having to create a random number from 0-360 and attach it to deg in the above statement?

@pitchernikki, this is a great question. I think assigning a random number to a variable and attaching it to the deg is your best option. I will pass this on to the curriculum team for clarity.

I tried to do that and I couldn’t get it to work. Please let me know if you find something that does. Thanks.

@pitchernikki,

Does this work? Not sure what you mean by not attaching it to deg…

Mike

1 Like

setStyle() takes string arguments. Those arguments are sent to the JavaScript interpreter running in your browser. The one that runs App Lab itself. You must build the string you want to send.

What I would do is create a function for it.

function setRotation(id, rotation) {
  setStyle(id, "transform:rotate("+rotation+"deg);");
}

Then you can rotate it with just a variable.

1 Like

Thank you so much for your help. That works great.