-
Notifications
You must be signed in to change notification settings - Fork 1
/
favourite.js
62 lines (50 loc) · 1.65 KB
/
favourite.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
let arr = JSON.parse(localStorage.getItem("Hotel")) || [];
document.querySelector("#stayy").textContent = arr.length + " Stays";
display(arr);
function display(arr) {
let container = document.querySelector("#items");
for (let i = 0; i < arr.length; i++) {
let div = document.createElement("div");
let banner = document.createElement("img");
banner.src = arr[i].hotelThumbnail;
let textsDiv = document.createElement("div");
//let search = localStorage.getItem("searchQuerry");
let city = document.createElement("p");
city.textContent = arr[i].hotelName;
let checkIn = localStorage.getItem("checkInDate");
let checkOut = localStorage.getItem("checkOutDate");
let duration = document.createElement("p");
duration.setAttribute("id", "info");
duration.textContent =
"Dates:" + getDay(checkIn) + " to " + getDay(checkOut);
textsDiv.append(city, duration);
var make = document.createElement("button");
make.addEventListener("click", function () {
bookitem(arr[i]);
});
make.setAttribute("class", "book");
make.innerHTML = "Book Now " + ` `;
div.append(banner, textsDiv, make);
container.append(div);
}
}
function getDay(a) {
let date = new Date(a);
let month = date.toLocaleString("default", { month: "short" });
let num = "";
for (let i = a.length - 1; i >= 0; i--) {
if (a[i] == "-") {
break;
}
num += a[i];
}
let gen = "";
for (let i = num.length - 1; i >= 0; i--) {
gen += num[i];
}
return gen + " " + month;
}
function bookitem(elem) {
localStorage.setItem("bookingdata", JSON.stringify(elem));
window.location.href = "booking.html";
}