0
0
Fork 0

Convert to tabs and switch to using Vue

This commit is contained in:
Oliver-Akins 2023-02-01 10:42:48 -06:00
parent e461a0a677
commit 0001dca6e7
5 changed files with 55 additions and 127 deletions

View file

@ -11,9 +11,7 @@
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<!-- JAVASCRIPT --> <!-- JAVASCRIPT -->
<script src="./js/delete_choice.js"></script> <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="./js/add_choice.js"></script>
<script src="./js/choosing.js"></script>
</head> </head>
<body> <body>
<template id="choice-template"> <template id="choice-template">

View file

@ -1,12 +0,0 @@
const add_choice = () => {
let index = document.getElementsByClassName("choice").length;
let choice_div = document.getElementById("choice-template");
let clone = choice_div.content.cloneNode(true);
clone.children[0].children[0].id = `text-in-${index}`;
clone.children[0].children[1].id = `weight-in-${index}`;
// Add to document without resetting the other ones
document.getElementById("choices").appendChild(clone);
};

View file

@ -1,55 +0,0 @@
const construct_choices = () => {
let choices = document.getElementById("choices").children;
let start_of_next_range = 1;
let options = [];
// Construct the array for choosing
for (choice of choices) {
let name = choice.children[0].value;
let weight = parseInt(choice.children[1].value);
if (Number.isNaN(weight)) {
break;
};
options.push({
"name": name,
"min": start_of_next_range,
"max": start_of_next_range + weight - 1
});
start_of_next_range += weight;
};
return {
"choices": options,
"max_value": start_of_next_range - 1
};
};
const choose_option = () => {
let {choices, max_value} = construct_choices();
// No options, error
if (choices.length === 0 && max_value === 0) {
document.getElementById("result").innerText = "\nERROR: No Choices to pick from";
return;
}
// Only one option exists, no need to waste time with randomness
else if (choices.length === 1) {
document.getElementById("result").innerText = choices[0].name
};
let chosen_value = Math.round(Math.random() * max_value);
// Find the choice which the randomly chosen number fits within
for (choice of choices) {
if (choice.min <= chosen_value <= choice.max) {
document.getElementById("result").innerText = choice.name;
return;
};
};
};

View file

@ -1,3 +0,0 @@
const delete_choice = (node) => {
node.parentElement.parentElement.removeChild(node.parentElement)
};