Can you help me with an issue I'm having? When attempting to rotate the blue square using a function, it only works once. After that, the page needs to be reloaded in order for the rotation function to work again. Additionally, after rotating 120 degrees with one click, the square resets itself back to its starting position.
I need assistance with two things:
- Fix the rotation function so it can be clicked multiple times without resetting.
- Prevent the square from automatically resetting its position.
I have created a fiddle with the code: https://jsfiddle.net/kv7may8t/2/
document.getElementById('button1').addEventListener('click', function() {
document.getElementById('blue').classList.add('rotateright');
});
Summary of the function: Click on button1 to activate the function that adds the "rotateright" class to the blue square, causing it to rotate by 120 degrees.