Codecademy Practice

Rock, Paper, Scissors - Part 2

We are going to add the floating faces now.

To practice: CSS animations with keyframes, modifying HTML attributes from JavaScript

Video showing the animations on the faces representing the human and the computer.

Step by step instructions

Download the images from here.

HTML

CSS

Faces

The images of the faces have an animation applied to them where they just go up and down forever. To make an animation like this, we will use the animation property (the shorthand). One of the values passed to the animation property is the animation name. We are going to use a custom name for the value of the animation name. We will declare this custom name using the @keyframes rule. Like this:

Shadow

JS

We want to switch the images depending on the result of playing the game. For this we are going to update the value of the src attribute of the images via JavaScript. We can do this by first getting the image element we want to update, and then calling .src on it and storing the path to the image, in the same way we do when we call .setContent to store some text in an element.

GIT

DEBUGGING