🐛 Fixed Score-thing
This commit is contained in:
@@ -29,14 +29,16 @@
|
||||
// let data_by_username = {};
|
||||
let score_by_username = {};
|
||||
|
||||
for (const i of new_data) {
|
||||
/* data_by_username[i.username] = {
|
||||
answer: i.answer,
|
||||
right: i.right,
|
||||
time_taken: i.time_taken,
|
||||
score: i.score
|
||||
};*/
|
||||
score_by_username[i.username] = i.score;
|
||||
const do_sth = () => {
|
||||
for (const i of new_data) {
|
||||
score_by_username[i.username] = i.score;
|
||||
}
|
||||
};
|
||||
|
||||
$: {
|
||||
new_data;
|
||||
score_by_username;
|
||||
do_sth();
|
||||
}
|
||||
|
||||
let player_names;
|
||||
@@ -56,7 +58,16 @@
|
||||
// for (let i = 0; i++; i < player_names.length) {
|
||||
// console.log(data)
|
||||
for (const i of player_names) {
|
||||
data[i] = score_by_username[i] + data[i];
|
||||
if (isNaN(data[i])) {
|
||||
data[i] = 0;
|
||||
}
|
||||
console.log(score_by_username[i], '1');
|
||||
data[i] = (score_by_username[i] ?? 0) + data[i];
|
||||
}
|
||||
for (const i of new_data) {
|
||||
if (!data[i.username]) {
|
||||
data[i.username] = score_by_username[i.username];
|
||||
}
|
||||
}
|
||||
show_new_score_clicked = true;
|
||||
setTimeout(() => {
|
||||
@@ -74,7 +85,6 @@
|
||||
</script>
|
||||
|
||||
<main>
|
||||
<button on:click={show_new_score}>Show new Score</button>
|
||||
<div class="flex justify-center">
|
||||
<div>
|
||||
<table class="table-auto text-xl">
|
||||
@@ -83,8 +93,8 @@
|
||||
<th class="p-2 border-b-2 border-b-black">Points</th>
|
||||
{#if show_new_score_clicked}
|
||||
<th in:fly={{ x: 300 }} class="p-2 border-b-2 border-b-black"
|
||||
>Points added</th
|
||||
>
|
||||
>Points added
|
||||
</th>
|
||||
{/if}
|
||||
</tr>
|
||||
{#each player_names as player, i (player)}
|
||||
@@ -96,9 +106,10 @@
|
||||
in:fly={{ x: 300 }}
|
||||
class:hidden={i > 3}
|
||||
class="p-2"
|
||||
class:text-red-600={score_by_username[player] === 0}
|
||||
class:text-red-600={score_by_username[player] === 0 ||
|
||||
score_by_username[player] === undefined}
|
||||
>
|
||||
+{score_by_username[player]}
|
||||
+{score_by_username[player] ?? '0'}
|
||||
</td>
|
||||
{/if}
|
||||
</tr>
|
||||
|
||||
@@ -31,24 +31,30 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: console.log(score_by_username, scores, 'dieter');
|
||||
for (const i of question_results) {
|
||||
score_by_username[i.username] = i.score;
|
||||
}
|
||||
|
||||
$: scores = sortObjectbyValue(scores);
|
||||
|
||||
for (const i of Object.keys(scores)) {
|
||||
scores[i] = score_by_username[i] + scores[i];
|
||||
}
|
||||
const do_sth = () => {
|
||||
for (const i of Object.keys(score_by_username)) {
|
||||
scores[i] = (score_by_username[i] ?? 0) + (scores[i] ?? 0);
|
||||
}
|
||||
scores = scores;
|
||||
};
|
||||
|
||||
do_sth();
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<div class="flex justify-center h-screen">
|
||||
<div class="m-auto flex flex-col">
|
||||
<p class="p-4 bg-black bg-opacity-40 rounded-lg text-2xl">
|
||||
+{score_by_username[username]}
|
||||
+{score_by_username[username] ?? '0'}
|
||||
</p>
|
||||
<p>Total score: {scores[username]}</p>
|
||||
<p>Total score: {scores[username] ?? '0'}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user