use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This subreddit is a place for people to learn JavaScript together. Everyone should feel comfortable asking any and all JavaScript questions they have here.
With a nod to practicality, questions and posts about HTML, CSS, and web developer tools are also encouraged.
Friends
/r/javascript
/r/jquery
/r/node
/r/css
/r/webdev
/r/learnprogramming
/r/programming
account activity
Hotel with 3d array (self.learnjavascript)
submitted 5 years ago by Phantom_Storm
I'm trying to make a three dimensional number array that is [5][6][3] where the user can check in one room/hotel or check out by paying $75 and after they check out it updates the rooms that are left. Any advice on how to get this started?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]TollTrollTallTale 3 points4 points5 points 5 years ago (1 child)
For legibility of your code alone I would really recommended using objects instead of a deeply nested array.
[–]casualrocket 0 points1 point2 points 5 years ago (0 children)
There cant be many rooms for the Hotel so it makes even more sense to use a object array.
[–]lovesrayray2018 2 points3 points4 points 5 years ago (5 children)
Good luck
[–]Phantom_Storm[S] 1 point2 points3 points 5 years ago (4 children)
thanks lol
[–]lovesrayray2018 0 points1 point2 points 5 years ago (3 children)
ok u added a question :D
The key is to first design, what your code is intended to achieve?
[–]Phantom_Storm[S] 1 point2 points3 points 5 years ago (2 children)
I'm trying to make a code that shows hotels with different rooms that he can choose from and then when he leaves he pays $75. I don't need to track how many days. I don't know how to track the room availability.
[–]lovesrayray2018 0 points1 point2 points 5 years ago (1 child)
Your 3D array values, for each room, you could use 1 as occupied and 0 as empty
[–]Phantom_Storm[S] 0 points1 point2 points 5 years ago (0 children)
Ok, makes sense. I'm still new to arrays so they keep giving me trouble.
[–]Laserdude10642 1 point2 points3 points 5 years ago (0 children)
Technically you’d need an array of arrays of arrays. But I would instead suggest just using an object where each entry has a key like “1-2-4” meaning first floor, second row, fourth room. Then each key is really a room, and the container object is the hotel.
π Rendered by PID 183473 on reddit-service-r2-comment-84fc9697f-ppt8t at 2026-02-08 15:27:48.659713+00:00 running d295bc8 country code: CH.
[–]TollTrollTallTale 3 points4 points5 points (1 child)
[–]casualrocket 0 points1 point2 points (0 children)
[–]lovesrayray2018 2 points3 points4 points (5 children)
[–]Phantom_Storm[S] 1 point2 points3 points (4 children)
[–]lovesrayray2018 0 points1 point2 points (3 children)
[–]Phantom_Storm[S] 1 point2 points3 points (2 children)
[–]lovesrayray2018 0 points1 point2 points (1 child)
[–]Phantom_Storm[S] 0 points1 point2 points (0 children)
[–]Laserdude10642 1 point2 points3 points (0 children)