mirror of
https://github.com/sveltejs/svelte.git
synced 2024-12-01 17:30:59 +01:00
fix flight booker example
This commit is contained in:
parent
a8e0a471af
commit
f863a5df30
@ -1,26 +1,24 @@
|
|||||||
<script>
|
<script>
|
||||||
const tomorrow = new Date(Date.now() + 86400000);
|
const tomorrow = new Date(Date.now() + 86400000);
|
||||||
|
|
||||||
const tomorrowAsString = [
|
let start = [
|
||||||
tomorrow.getFullYear(),
|
tomorrow.getFullYear(),
|
||||||
pad(tomorrow.getMonth() + 1, 2),
|
pad(tomorrow.getMonth() + 1, 2),
|
||||||
pad(tomorrow.getDate(), 2)
|
pad(tomorrow.getDate(), 2)
|
||||||
].join('-');
|
].join('-');
|
||||||
|
|
||||||
let start = tomorrowAsString;
|
let end = start;
|
||||||
let end = tomorrowAsString;
|
|
||||||
let isReturn = false;
|
let isReturn = false;
|
||||||
|
|
||||||
const startDate = () => convertToDate(start);
|
$: startDate = convertToDate(start);
|
||||||
const endDate = () => convertToDate(end);
|
$: endDate = convertToDate(end);
|
||||||
|
|
||||||
|
|
||||||
function bookFlight() {
|
function bookFlight() {
|
||||||
const type = isReturn ? 'return' : 'one-way';
|
const type = isReturn ? 'return' : 'one-way';
|
||||||
|
|
||||||
let message = `You have booked a ${type} flight, leaving ${startDate().toDateString()}`;
|
let message = `You have booked a ${type} flight, leaving ${startDate.toDateString()}`;
|
||||||
if (type === 'return') {
|
if (type === 'return') {
|
||||||
message += ` and returning ${endDate().toDateString()}`;
|
message += ` and returning ${endDate.toDateString()}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
alert(message);
|
alert(message);
|
||||||
@ -57,5 +55,5 @@
|
|||||||
|
|
||||||
<button
|
<button
|
||||||
on:click={bookFlight}
|
on:click={bookFlight}
|
||||||
disabled="{isReturn && (startDate() >= endDate())}"
|
disabled="{isReturn && (startDate >= endDate)}"
|
||||||
>book</button>
|
>book</button>
|
||||||
|
Loading…
Reference in New Issue
Block a user