Skip to content

Commit

Permalink
score result
Browse files Browse the repository at this point in the history
  • Loading branch information
sivaprasath2004 authored Jul 22, 2024
1 parent b3b6bf9 commit 5c40015
Showing 1 changed file with 37 additions and 36 deletions.
73 changes: 37 additions & 36 deletions Games/WordChain/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,71 @@
let timelimit = 30;
let time = 0;
var threading;
let previousWord = '';
const wordList = document.getElementById('word-list');
const message = document.getElementById('message');
let previousWord = "";
const wordList = document.getElementById("word-list");
const message = document.getElementById("message");
let score = 0;


setTimeout(()=>{
let Intro_page=document.getElementById('Intro_page')
Intro_page.style.transform="translateX(-100%)"
},3000)
function playTurn() {
const inputWord = document.getElementById('input-word').value;
clearInterval(threading);
threading=setInterval(function() {
const inputWord = document.getElementById("input-word").value;
clearInterval(threading);
threading = setInterval(function () {
time += 0.01;
if(time>=timelimit)
{
clearInterval(threading);
document.getElementById("countdown").innerHTML = "";
message.textContent = `Game Over! Your score is ${score}.`;
}
else
document.getElementById("countdown").innerHTML=time.toPrecision(4);
}, 10);
if (inputWord === '') {
message.textContent = 'Please enter a word.';
if (time >= timelimit) {
clearInterval(threading);
document.getElementById("countdown").innerHTML = "";
message.textContent = `Game Over! Your score is ${score}.`;
} else document.getElementById("countdown").innerHTML = time.toPrecision(4);
}, 10);
if (inputWord === "") {
message.textContent = "Please enter a word.";
return;
}
if (previousWord === '') {

if (previousWord === "") {
previousWord = inputWord;
addWordToList(inputWord);
document.getElementById('input-word').value = '';
message.textContent = '';
document.getElementById("input-word").value = "";
message.textContent = "";
} else {
const lastChar = previousWord.charAt(previousWord.length - 1);
const firstChar = inputWord.charAt(0);
if (lastChar.toLowerCase() === firstChar.toLowerCase()) {
score++;
previousWord = inputWord;
addWordToList(inputWord);
document.getElementById('input-word').value = '';
message.textContent = '';
document.getElementById("input-word").value = "";
message.textContent = "";
} else {
// clearInterval(threading);
score=`${(100 - time)/10}`
console.log(time,score)
document.getElementById("countdown").innerHTML = "";
time = 0;
clearInterval(threading);
document.getElementById("countdown").innerHTML = "";
message.textContent = `Game Over! Your score is ${score}.`;
message.textContent = `Game Over! Your score is ${score.slice(0,4)}`;
time = 0;
score=0
}
}
}

function addWordToList(word) {
const listItem = document.createElement('li');
const listItem = document.createElement("li");
listItem.textContent = word;
wordList.appendChild(listItem);
}

function restart(){
time=0;
previousWord = '';
wordList.innerHTML = '';
document.getElementById('input-word').value = '';
message.textContent = '';
function restart() {
time = 0;
previousWord = "";
wordList.innerHTML = "";
document.getElementById("input-word").value = "";
message.textContent = "";
score = 0;
document.getElementById("countdown").innerHTML = "";
clearInterval(threading);
//document.getElementById('word-list').style.display = 'none';
}
}

0 comments on commit 5c40015

Please sign in to comment.