Skip to content

Commit fa35aef

Browse files
Fixing a few errors.
1 parent 3936760 commit fa35aef

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,7 @@ dist
127127
.yarn/unplugged
128128
.yarn/build-state.yml
129129
.yarn/install-state.gz
130-
.pnp.*
130+
.pnp.*
131+
132+
# ignore .idea
133+
.idea

build.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
<meta charset="UTF-8">
55
<title>Sorting algorithm</title>
66
<script src="src/sorting.js"></script>
7-
<link href="build.css" rel="stylesheet">
7+
<link href="dist/output.css" rel="stylesheet">
88
</head>
99
<body >
1010
<div class="m-10 xl:grid xl:grid-cols-2 xl:justify-items-stretch w-[95%] h-full">
1111
<div class="text-2xl">
1212
<h1 class="text-5xl font-mono">Sorting algorithms</h1>
1313
<div class="p-6 mt-3 grid grid-cols-1 gap-1">
14-
<input class="shadow-sm border-gray-300 rounded-lg m-2 focus:ring-2 focus:ring-indigo-200 focus:border-indigo-400" type="text" id="input" placeholder="Enter numbers to sort">
15-
<button class="p-2 px-5 bg-black text-gray-400" onclick="sort()">Sort</button>
16-
<button class="p-2 px-5 bg-black text-gray-400" onclick="reset()">Reset</button>
14+
<input class="border-2 border-black rounded-lg p-1" type="text" id="input" placeholder="Enter amount to sort">
15+
<button class="p-2 px-5 bg-black text-gray-400 rounded-lg" onclick="sort()" id="start-sort-btn">Sort</button>
1716
</div>
1817
<div>
1918
<h2 class="text-5xl font-mono">Stats</h2>
@@ -31,22 +30,23 @@ <h2 class="text-5xl font-mono">Stats</h2>
3130
<canvas class="bg-black p-5 w-full h-full" id="canvas" width="1000" height="1000" ></canvas>
3231
</div>
3332
</div>
33+
3434
<div class="text-2xl m-10">
3535
<h3 class="text-5xl my-5">
3636
Further Settings
3737
</h3>
38-
<input class="border-black border-2 rounded-lg" type="text" id="speed" placeholder="speed">
38+
<input class="border-2 border-black rounded-lg p-1 p-" type="text" id="speed" placeholder="time between iteration">
3939
<select name="sorting-algorithm" id="sorting-algorithm">
4040
<option class="text-lg" value="bubble-sort">Bubble sort</option>
4141
<option class="text-lg" value="insertion-sort">Insertion sort</option>
4242
<option class="text-lg" value="selection-sort">Selection sort</option>
4343
</select>
44-
<button onclick="updateSettings()">Update Settings</button>
44+
<button class="border-2 border-black rounded-lg p-1 ml-5" onclick="updateSettings()">Update Settings</button>
4545
</div>
46-
<footer class="text-2xl mt-auto">
46+
<footer class="text-3xl mt-auto">
4747
<div class="bg-black">
4848
<div class="flex flex-row items-center justify-between py-4 ">
49-
<p class="text-lg text-gray-400 ">© 2023 Mauritz Orlinski</p>
49+
<p class="text-gray-400 ">© 2023 Mauritz Orlinski</p>
5050
<div class="flex text-gray-200">
5151
<a class="mr-4 hover:scale-110" href="https://github.com/MauritzOrlinski">GitHub</a>
5252
<a class="mr-4 hover:scale-110" href="https://mauritzorlinski.com">mauritzorlinski.com</a>

src/sorting.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,19 @@ function reset() {
146146
document.getElementById("isSorted").innerHTML = "False";
147147
const numberOfElements = document.getElementById("input").value;
148148
updateVisualisation([]);
149+
document.getElementById("start-sort-btn").innerHTML = "Sort";
149150
}
150151

151152
function sort() {
153+
document.getElementById("start-sort-btn").innerHTML = "Reset";
152154
if (isRunning) {
153-
alert("Already running! Press reset to stop.");
155+
reset();
154156
return;
155157
}
156158
isRunning = true;
157159
let numberOfElements = document.getElementById("input").value;
158-
if (isNaN(numberOfElements) || numberOfElements === "") {
159-
alert("Must input numbers, otherwise the default value of 100 will be used.");
160+
if (isNaN(numberOfElements) || numberOfElements === "" || numberOfElements < 0) {
161+
alert("Must input an Integer, otherwise the default value of 100 will be used.");
160162
numberOfElements = 100;
161163
}
162164
document.getElementById("arraySize").innerHTML = numberOfElements;
@@ -192,10 +194,10 @@ async function isSorted(array) {
192194

193195
function updateSettings() {
194196
sleepTime = document.getElementById("speed").value;
195-
if (isNaN(sleepTime)) {
196-
alert("Must input a number for the running speed, otherwise the default value of 10 will be used.");
197+
if (isNaN(sleepTime) || sleepTime < 0) {
198+
alert("Must input an Integer for the wait time, otherwise the default value of 10 will be used.");
197199
sleepTime = 10;
198200
}
199201
selectedAlgorithm = document.getElementById("sorting-algorithm").value;
200-
console.log(selectedAlgorithm);
202+
reset();
201203
}

0 commit comments

Comments
 (0)