Answers for "onclick display array value javascript"

0

onclick display array value javascript

<div id="wrapper">
  <div class="quotes">
    <p id="par"></p>
  </div>

  <button class="btn" onClick="randomQuote()">button</button>
</div>
Posted by: Guest on August-12-2020
0

onclick display array value javascript

var array = [1,20,50,100];
var cpt = 0;

//Init the 'par' div before click
document.querySelector("#par").innerHTML = array[cpt];

function randomQuote () 
{
  if(cpt<array.length-1)
    cpt++;
  else
    cpt=0;

  document.querySelector("#par").innerHTML = array[cpt];
}
Posted by: Guest on August-12-2020

Code answers related to "onclick display array value javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language