78 lines
2.9 KiB
JavaScript
78 lines
2.9 KiB
JavaScript
// client.ts
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
// Event handler for Guess button
|
|
function guessNumber() {
|
|
const guessInput = document.getElementById('guessInput');
|
|
const guessValue = guessInput.value;
|
|
if (guessValue === '') {
|
|
displayResult('Please enter a valid number!');
|
|
return;
|
|
}
|
|
// Hier sendest du die Anfrage an den Server
|
|
fetch(`http://localhost:8080/guess/${guessValue}`, {
|
|
method: 'GET'
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
console.log(data);
|
|
displayResult(data.answer);
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
});
|
|
}
|
|
// Event handler for Cheat button
|
|
function cheat() {
|
|
const passwordInput = document.getElementById('passwordInput');
|
|
const passwordValue = passwordInput.value;
|
|
// Hier sendest du die Anfrage an den Server
|
|
fetch('http://localhost:8080/cheat', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({ password: passwordValue }),
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
// Hier wird die Antwort des Servers in einem sichtbaren Bereich angezeigt
|
|
displayResult(data.message);
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
});
|
|
}
|
|
// Event handler for Reset button
|
|
function resetValues() {
|
|
const minInput = document.getElementById('minInput');
|
|
const maxInput = document.getElementById('maxInput');
|
|
const minValue = minInput.value;
|
|
const maxValue = maxInput.value;
|
|
// Hier sendest du die Anfrage an den Server
|
|
fetch('http://localhost:8080/reset', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({ min: minValue, max: maxValue }),
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
// Hier wird die Antwort des Servers in einem sichtbaren Bereich angezeigt
|
|
displayResult(data.message);
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
});
|
|
}
|
|
// Funktion zur Anzeige der Serverantwort
|
|
function displayResult(message) {
|
|
const resultElement = document.getElementById('result');
|
|
resultElement.innerText = message;
|
|
}
|
|
// Attach click event handlers to buttons
|
|
document.getElementById('button-addon1').addEventListener('click', guessNumber);
|
|
document.getElementById('button-addon2').addEventListener('click', cheat);
|
|
document.getElementById('button-addon4').addEventListener('click', resetValues);
|
|
});
|
|
//# sourceMappingURL=client.js.map
|