-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4dc335
commit 556278b
Showing
3 changed files
with
114 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,76 @@ | ||
const numbers = [ | ||
{ n: 1, selected: false }, | ||
{ n: 6, selected: false }, | ||
{ n: 8, selected: false }, | ||
{ n: 7, selected: false }, | ||
{ n: 2, selected: false }, | ||
{ n: 3, selected: false }, | ||
{ n: 5, selected: false }, | ||
{ n: 4, selected: false }, | ||
]; | ||
|
||
const root = document.querySelector("#root"); | ||
const wizard = document.querySelector("#wizard"); | ||
|
||
function init() { | ||
root.innerHTML = ""; | ||
|
||
let all = true; | ||
for (const i in numbers) { | ||
const n = numbers[i] | ||
if (n.n - 1 !== Number(i)) { | ||
all = false | ||
} | ||
} | ||
if (all) { | ||
wizard.classList.add("success") | ||
} | ||
|
||
for (const i in numbers) { | ||
const n = numbers[i] | ||
const step = document.createElement("div"); | ||
step.id = n.n; | ||
step.innerText = n.n; | ||
step.classList.add("step") | ||
|
||
if (n.n - 1 === Number(i)) { | ||
step.classList.add("correct") | ||
} | ||
|
||
root.appendChild(step); | ||
step.addEventListener('click', function(e) { | ||
this.classList.toggle("selected"); | ||
if (n.selected) { | ||
n.selected = false | ||
return | ||
} | ||
|
||
n.selected = true | ||
|
||
for (const j in numbers) { | ||
if (j === i) { | ||
continue | ||
} | ||
|
||
const n2 = numbers[j] | ||
if (n2.selected) { | ||
n.selected = false | ||
n2.selected = false | ||
numbers[j] = n | ||
numbers[i] = n2 | ||
|
||
init() | ||
break | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
init() | ||
|
||
{ n: 1, selected: false }, | ||
{ n: 6, selected: false }, | ||
{ n: 8, selected: false }, | ||
{ n: 7, selected: false }, | ||
{ n: 2, selected: false }, | ||
{ n: 3, selected: false }, | ||
{ n: 5, selected: false }, | ||
{ n: 4, selected: false }, | ||
]; | ||
const root = document.querySelector("#root"); | ||
const wizard = document.querySelector("#wizard"); | ||
|
||
function init() { | ||
root.innerHTML = ""; | ||
|
||
let all = true; | ||
|
||
for (const i in numbers) { | ||
const n = numbers[i]; | ||
|
||
if (n.n - 1 !== Number(i)) { | ||
all = false; | ||
} | ||
} | ||
|
||
if (all) { | ||
wizard.classList.add("success"); | ||
} | ||
|
||
for (const i in numbers) { | ||
const n = numbers[i]; | ||
const step = document.createElement("div"); | ||
|
||
step.id = n.n; | ||
step.innerText = n.n; | ||
step.classList.add("step"); | ||
|
||
if (n.n - 1 === Number(i)) { | ||
step.classList.add("correct"); | ||
} | ||
|
||
root.appendChild(step); | ||
step.addEventListener("click", function(e) { | ||
this.classList.toggle("selected"); | ||
|
||
if (n.selected) { | ||
n.selected = false; | ||
|
||
return; | ||
} | ||
|
||
n.selected = true; | ||
|
||
for (const j in numbers) { | ||
if (j === i) { | ||
continue; | ||
} | ||
|
||
const n2 = numbers[j]; | ||
|
||
if (n2.selected) { | ||
n.selected = false; | ||
n2.selected = false; | ||
numbers[j] = n; | ||
numbers[i] = n2; | ||
init(); | ||
|
||
break; | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
|
||
init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters