title: javascript for loop to use a function for several objects
body: <p>I am working on a game that has three dice cubes that show random faces upon clicking a button.
  Images are by css image sprite. If the random number gets 1 the dice cube is assigned to a css class that has its image sprite.</p>
  
  <pre><code>function diceroll (){
  
      var randomnumber = Math.floor(Math.random() * (6 - 1 + 1)) + 1;
  
          switch (randomnumber) {
  
          case 1:
              document.getElementById("dice1").setAttribute("class", "face1");
              break;
          case 2:
              document.getElementById("dice1").setAttribute("class", "face2");
              break;
          case 3:
              document.getElementById("dice1").setAttribute("class", "face3");
              break;
          case 4:
              document.getElementById("dice1").setAttribute("class", "face4");
              break;
          case 5:
              document.getElementById("dice1").setAttribute("class", "face5");
              break;
          case 6:
              document.getElementById("dice1").setAttribute("class", "face6");
              break;
      }
  }
  </code></pre>
  
  <p>I have a separate button, when clicked it should run the above diceroll function to the three divs with ids dice1, dice2 and dice3.</p>
  
  <p>I want to use</p>
  
  <pre><code>function gotoloop (){
  
      for (i = 0; i &lt; 2; i++) {
          // the code that affects dice(n) and n=1 and then diceroll function
          // affects dice1 n+1
      }
  
  }
  </code></pre>
  
  <p>I researched and could not find a way to implement the code for the last commented two lines. Please let me know if my approach is correct and help me with the code.</p>