-
Notifications
You must be signed in to change notification settings - Fork 0
/
text9.js
69 lines (66 loc) · 1.89 KB
/
text9.js
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
var score1 = document.querySelector("#s1");
var player1 = document.querySelector("#p1");
var num1 = 0;
var score2 = document.querySelector("#s2");
var player2 = document.querySelector("#p2");
var num2 = 0;
var reset = document.querySelector("#res");
var winner = document.querySelector("#winner");
//var winner1 = document.getElementById("winner");
var limit = +document.querySelector("#limit").value;
player1.addEventListener("click", myFunction);
function myFunction() {
// var limit = +document.querySelector("#limit").value;
if (num1 <= limit) {
console.log("if");
num1++;
score1.textContent = num1;
} else {
if (num1 == limit || num1 > num2) {
console.log("else if");
// document.write(winner + "player1");
winner.textContent = "player1";
player1.disabled = true;
}
}
}
player2.addEventListener("click", myFunction1);
function myFunction1() {
//var limit = document.querySelector("#limit");
if (num2 <= limit) {
num2++;
score2.textContent = num2;
} else {
if (num2 == limit || num2 > num1) {
winner.textContent = "player2";
player2.disabled = true;
}
}
}
reset.addEventListener("click", myfunction3);
function myfunction3() {
document.getElementById("myForm").reset();
num2 = 0;
num1 = 0;
score1.textContent = num1;
score2.textContent = num2;
winner.textContent = "";
}
var h1 = document.getElementById("t1");
h1.setAttribute("style", "background:red");
h1.style.color = "white";
/*var span = document.getElementById("s1");
span.style.fontSize = "40px";
span.style.fontFamily = "arial";
span.style.color = "yellow";
span.setAttribute("style", "fontSize:120px");
var b1 = getElementById("body");
b1.addEventListener("click", myfunction2);
function myfunction2() {
alert("hey");
}
var t2 = document.getElementById("t2");
t2.style.backgroundColor = black;
t2.style.color = white;
t2.setAttribute("style", "backgroundColor:red");
*/