onclick display array value javascript

Solutions on MaxInterview for onclick display array value javascript by the best coders in the world

showing results for - "onclick display array value javascript"
Samuel
26 Aug 2020
1<div id="wrapper">
2  <div class="quotes">
3    <p id="par"></p>
4  </div>
5
6  <button class="btn" onClick="randomQuote()">button</button>
7</div>
Julian
09 May 2019
1var array = [1,20,50,100];
2var cpt = 0;
3
4//Init the 'par' div before click
5document.querySelector("#par").innerHTML = array[cpt];
6
7function randomQuote () 
8{
9  if(cpt<array.length-1)
10    cpt++;
11  else
12    cpt=0;
13
14  document.querySelector("#par").innerHTML = array[cpt];
15}