Skip to content

Commit

Permalink
Switched any types to strictier ones
Browse files Browse the repository at this point in the history
  • Loading branch information
timhaj committed May 1, 2024
1 parent bf537b6 commit fe7c71b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions color.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
let containerDiv: any = document.createElement("div");
let containerDiv: HTMLDivElement = document.createElement("div");
containerDiv.setAttribute("class", "container");
let guess: number = Math.floor(Math.random() * 5);
let available: string[] = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"];
let colors: string[] = generateRandomColors();
let flag: boolean = false;
let info: any = document.createElement("p");
let info: HTMLParagraphElement | HTMLButtonElement = document.createElement("p");
info.setAttribute("id", "guessingColor");
info.innerHTML = colors[guess];
containerDiv.appendChild(info);

let colorDiv: any = document.createElement("div");
let colorDiv: HTMLDivElement = document.createElement("div");
colorDiv.setAttribute("class", "colorContainer");

for (let i = 0; i < 5; i++) {
let circleDiv: any = document.createElement("div");
let circleDiv: HTMLDivElement = document.createElement("div");
circleDiv.setAttribute("class", "circle");
circleDiv.style.backgroundColor = colors[i];
circleDiv.addEventListener("click", () => {
Expand All @@ -28,7 +28,7 @@ info.innerHTML = "Guess the correct color";
containerDiv.appendChild(info);
document.body.appendChild(containerDiv);

function check(element: any): void {
function check(element: HTMLDivElement): void {
let barve: string[] = element.style.backgroundColor.substring(4, element.style.backgroundColor.length - 1).split(",");
let R: string = parseInt(barve[0], 10).toString(16).toUpperCase().padStart(2, "0");
let G: string = parseInt(barve[1], 10).toString(16).toUpperCase().padStart(2, "0");
Expand All @@ -46,7 +46,7 @@ function check(element: any): void {
info.setAttribute("id", "win");
info.innerHTML = "You're correct!";
containerDiv.replaceChild(info, containerDiv.childNodes[2]);
let a: any = document.createElement("a");
let a: HTMLAnchorElement = document.createElement("a");
a.setAttribute("href", "/color.html");
info = document.createElement("button");
info.setAttribute("id", "btn");
Expand Down
12 changes: 6 additions & 6 deletions font.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let container: any = document.createElement("div");
let container: HTMLDivElement = document.createElement("div");
container.setAttribute("class", "container");
let fontToGuess: number = Math.floor(Math.random() * 5);

Expand Down Expand Up @@ -34,16 +34,16 @@ let fonts: string[] = [

let guessingFonts: string[] = generateRandomFonts();
let gameWin: boolean = false;
let element: any = document.createElement("p");
let element: HTMLParagraphElement | HTMLButtonElement = document.createElement("p");
element.setAttribute("id", "guessingFont");
element.innerHTML = guessingFonts[fontToGuess];
container.appendChild(element);

let fontDiv: any = document.createElement("div");
let fontDiv: HTMLDivElement = document.createElement("div");
fontDiv.setAttribute("class", "fontContainer");

for (let i = 0; i < 5; i++) {
let text: any = document.createElement("p");
let text: HTMLParagraphElement = document.createElement("p");
text.setAttribute("class", "font");
text.innerHTML = "Sample";
text.style.fontFamily = guessingFonts[i];
Expand All @@ -59,7 +59,7 @@ element.innerHTML = "Guess the correct font";
container.appendChild(element);
document.body.appendChild(container);

function handle(selected: any): void {
function handle(selected: HTMLParagraphElement): void {
let selectedFont: string = selected.style.fontFamily;
if (selectedFont == guessingFonts[fontToGuess] || selectedFont.substring(1, selectedFont.length - 1) == guessingFonts[fontToGuess]) {
if (!gameWin) {
Expand All @@ -73,7 +73,7 @@ function handle(selected: any): void {
element.setAttribute("id", "win");
element.innerHTML = "You're correct!";
container.replaceChild(element, container.childNodes[2]);
let a: any = document.createElement("a");
let a: HTMLAnchorElement = document.createElement("a");
a.setAttribute("href", "/font.html");
element = document.createElement("button");
element.setAttribute("id", "btn");
Expand Down

0 comments on commit fe7c71b

Please sign in to comment.