-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
103 lines (91 loc) · 3.38 KB
/
index.html
File metadata and controls
103 lines (91 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scramble Word</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Carter+One&family=Source+Sans+Pro:wght@300&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Word Scramble For Programming Language</h1>
</header>
<section>
<div class="gameArea">
<h3 class="msg"></h3>
<input type="text" class="hidden" />
<button class ="btn">Click here to Start</button>
</div>
</section>
<script>
if (document.addEventListener)
{
document.addEventListener('contextmenu', function (e) { e.preventDefault();}, false);
}
else
{
document.attachEvent('oncontextmenu', function () { window.event.returnValue = false;});
}
const msg=document.querySelector('.msg');
const guess=document.querySelector('input');
const btn =document.querySelector('.btn');
let play=false;
let words = ['python','javascript','c++','c#','html','css','reactjs','swift','ruby','java','php','angular','sql','express','android','nodejs','dart','kotlin','perl','pascal','nosql','typescript'];
let newWords = "";
let ranWords = "";
const createNewWords = () => {
let ranNum = Math.floor(Math.random() * words.length);
let newTempWords = words[ranNum];
return newTempWords;
}
const scrambleWords = (arr) => {
// for scrambling of array index
for (let i = arr.length-1; i>0; i--)
{
let temp = arr[i];
//console.log(temp)
let j = Math.floor(Math.random()*(i+1));
// console.log(i);
// console.log(j);
arr[i] = arr[j];
arr[j] = temp;
}
return arr;
}
btn.addEventListener('click', function(){
if(!play)
{
play = true;
btn.innerText ="Guess";
guess.classList.toggle('hidden')
newWords =createNewWords();
ranWords = scrambleWords(newWords.split("")).join("");
//console.log(ranWords.join("")); // for scrambling
msg.innerHTML = `Guess the Word: ${ranWords}`;
}
else
{
let tempWord = guess.value;
if(tempWord === newWords)
{
//console.log("Correct");
play = false;
msg.innerHTML = `It's Correct !! It is ${newWords}`;
btn.innerHTML = "Start Again";
guess.classList.toggle('hidden')
guess.value="";
}
else
{
//console.log("Wrong");
msg.innerHTML = `It's incorrect !! Please try again ${ranWords}`;
}
}
})
</script>
</body>
</html>