| document.getElementById("submit").addEventListener("click", function() { | |
| let dilemma = document.getElementById("dilemma").value; | |
| if (dilemma.trim() === "") { | |
| alert("Please enter a dilemma."); | |
| return; | |
| } | |
| fetch("/solve_dilemma", { | |
| method: "POST", | |
| headers: { | |
| "Content-Type": "application/json" | |
| }, | |
| body: JSON.stringify({ dilemma: dilemma }) | |
| }) | |
| .then(response => response.json()) | |
| .then(data => { | |
| document.getElementById("solution").innerText = "Solution: " + data.solution; | |
| }) | |
| .catch(error => { | |
| console.error("Error:", error); | |
| alert("Something went wrong! Check the console for details."); | |
| }); | |
| }); | |