Skip to content
Related Articles
Open in App
Not now

Related Articles

JavaScript Responsive time of an event

Improve Article
Save Article
  • Last Updated : 13 Dec, 2022
Improve Article
Save Article

Responsive time of an event is the time taken to load the result of that event and the time taken to start that event. In this post, various shapes have been used using Math.random() function. The task is to find out the responsive time of changing these shapes. As soon as you click the shape, it gets disappears and shows the response time on the top of the web page and a new shape get appears while the previous one gets disappeared. 

JavaScript code to change the shapes and find their responsive time 

Example: In this example, we will see the response time of loading of each shape on the screen


<style type="text/css">
    #s1 {
        height: 200px;
        width: 200px;
        border-radius: 50%;
        display: none;
    #s2 {
        height: 200px;
        width: 200px;
        display: none;
    #s3 {
        height: 140px;
        width: 200px;
        display: none;
    #button {
        position: absolute;
        left: 100px;
        top: 100px;
        height: 70px;
        width: 300px;
        font-size: 25px;
        background-color: darkseagreen;
<button id="button" onclick="myfun()">START GAME</button>
<p id="time"></p>
<div id="s1"></div>
<div id="s2"></div>
<div id="s3"></div>
<script type="text/javascript">
    function myfun() {
        var shape=Math.floor((Math.random()*3)+1);
        var shape1="s"+shape;
        var a=new Array(6);
        var text="";
        for(i=0;i<6;i++) {
            if(a[i]==10) {
            } else if(a[i]==11) {
            } else if(a[i]==12) {
            } else if(a[i]==13) {
            } else if(a[i]==14) {
            } else if(a[i]==15) {
            } else {
        var a=document.getElementById(shape1);
        document.getElementById(shape1).onclick=function() {
            var diff=end-start;
            var diff1=diff/1000;



My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!