Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html lang="fa" dir="rtl">
    <head>
        <title>speed test</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link href="./style.css" rel="stylesheet">
 
    </head>
    <body>
        <header>
            <h1 class="title">تست سرعت تایپ</h1>
            <p class="title_intro">فرایند سنجش سرعت تایپ با شروع تایپ کاربر، تایمر شروع به کار کرده و با تایپ هر حرف توسط کاربر مطابقت متن کاربر با متن نمایش داده شده چک می شود.</p>
        </header>
        <main class="test_area">
            <p class="patern">متن الگو:</p>
            <p class="patern_origin">the text to test.</p>
            
            <div class="test_wrapper">
                <textarea class="text_input" rows="6" placeholder="با تایپ اولین حرف تایمر شروع به کار میکند"></textarea>
            </div>
            <div class="flexcontainer">
                <button class="start">شروع مجدد</button>
                <div class="timer">00:00:00</div>
            </div>
        
        </main>
    <script src="./script.js"></script>
    </body>
</html>
 
* {
    font-family: iranyekan;
    margin: 0;
    box-sizing: border-box;
}
.title {
    text-align: center;
    background-color:aquamarine;
    padding: 2.5em;
    
}
.title_intro {
    padding: 2em;
    background-color: darkgreen;
    text-align: center;
    color: aliceblue;
}
.test_area {
    margin: 1em auto;
    width: 80%;
    padding: 3em auto;
}
.patern_origin {
    background-color: antiquewhite;
    direction: ltr;
    border: 1px solid green;
    border-radius: 4px;
    padding: .5em 1em;
    margin-bottom: 1em;
    width: 100%;
}
.test_wrapper{
 border: 10px solid grey;
 border-radius: 5px;
}
.text_input {
    width: 100%;
    font-size: 1.5em;
    direction: ltr;
    text-align: center;
}
.flexcontainer {
    align-items: center;
    display: flex;
    justify-content: space-between;
}
 .start {
    margin-top: 20px;
    font-family: inherit;
    padding: 0.5em 1em;
    font-size: larger;
    height: fit-content ;
    border-radius: 5px;
    box-shadow: 3px 3px 3px black;
    background-color: aquamarine;
 }
 .timer {
    direction: ltr;
    font-size: 3em;
    padding: 5px 20px;
    margin-top: 20px;
    color:brown;
    background-color: antiquewhite;
    border: 1px solid green;
    border-radius: 5px;
 }
 
const theTimer = document.querySelector('.timer');
const testArea = document.querySelector(".text_input");
const originText = document.querySelector(".patern_origin");
const testWrapper = document.querySelector('.test_wrapper');
var timer=[0,0,0,0];
var timerRunning=false;
var interval;
function leadingTime(time){
    if(time<=9){
        time="0"+time;
    }
    return time;
}
function runTimer (){
    let currentTime = leadingTime(timer[0])+":"+leadingTime(timer[1])+":"+leadingTime(timer[2]);
    theTimer.innerHTML = currentTime;
    
    timer[3]++;
    timer[0]=Math.floor((timer[3]/100)/60);
    timer[1]=Math.floor(timer[3]/100)-(timer[0]*60);
    timer[2]=Math.floor(timer[3]-(timer[1]*100)-(timer[0]*6000));
    
}
function spellCheck(){
    let textEntered=testArea.value;
    let originTextMatch=originText.substring ( '0' , textEntered.length);
    if(textEntered==originText){
        testWrapper.style.borderColor="green";
        clearInterval(interval);
    }else{
        if(textEntered==originTextMatch){
            testWrapper.style.borderColor="yellow";
        }else{
            testWrapper.style.borderColor="red";
        }
    }
}
function start (){
    let textEnteredLength = testArea.value.length;
    if (textEnteredLength==0 && !timerRunning)
    {
        timerRunning=true;
        interval = setInterval(runTimer,10);
    }
}
 testArea.addEventListener("keypress", start);  
 testArea.addEventListener("keyup", spellCheck);
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers