Find Your Hat Challenge Project (JavaScript)

Hi, this is my solution!
Hope your feedback…
I would like to know how to update the field without printing again! Thanks!

I feel totally the same. It really makes me feel deflated when everybody else can just recall everything and say "Oh okay, heres everything i’ve learnt, implemented into this project. And here I am with a blank stare.

2 Likes

https://github.com/gizmotehcat/find-your-hat

Any feedback would be appreciated! :slight_smile:

Hi mr_robot,

I politely disagree with “Oh okay, heres everything i’ve learnt, implemented into this project.”. The whole point of this project is to make you start thinking like a professional developer and to break down the project into chunks.

If you understand data types, classes, conditional statements and logical operators then you can complete this project. And I still googled, used stack overflow etc to complete it as I can not remember all the syntax I have covered.

Remember!! You are not expected to remember all the syntax, but to remember the underlying logic.

For me, I started by staring at the screen for about an hour, the breakthrough came once I realised that I could use the field array to create a positioning system for the player to track and record his movements.

I know you can complete it!

2 Likes

hi everyone
here is my basic version of findyourhat

I failed on this project massively! Couldn’t get my head around it at all.

I understand the principles behind it, but I found this a huge step up, from what we have been learning so far in this course.
An explanation/run through video is needed for this as we’ve had previously. Feeling a bit disheartended to see so many people who have completed it, whereas I failed… - I’m obviously not as far as I thought I was .

The solution uses code that hasn’t been mentioned before as well (or I missed it) - can anyone explain to me what the double [] do in the constructor here and what the double [0] [0] mean on the last line as well??

class Field {
constructor(field = []) {
this.field = field;
this.locationX = 0;
this.locationY = 0;
// Set the “home” position before the game starts
this.field[0][0] = pathCharacter;

thanks for any help!

4 Likes

hey @martyg_london , you dont need that [] in the constructor, it’s just a parameter, it can be anything. Take a look at my post a few posts above yours. I’ve outlined the steps in more detail.

2 Likes

thanks @edpho - I sepnt most of the day going through the official solution and others solutions and thankfully I understand 95% of it now - still not sure I could recreate it myself. I’ll read your post and revisit this project later on during the course and see if I can do any better (I blame the lack of concentration due to Homeschooling!!)

I’m still not completly clear on how you create a grid field from arrays and log them without the comma , at the end of each line… I’ll persevere…

cheers again for taking the time to reply!

Well, I’ve done it. Took me about three days in total to get this together, but I have a working, playable, game.

Here is the link to the playable version:
https://alexwojtak.github.io/hatFinder/

And the link to the repo:

All feedback is welcome!

I did realise during this what is meant by writing to the DOM being ‘expensive’. I thought I’d make it viewable on a webpage, but if you try and write an array of sprites one at a time in an array, even in a medium game grid, page load time takes several seconds. I had to bundle all the writing into one go to draw the level. Kind of handy practice ahead of the React modules to see why React is beneficial.

4 Likes

When I first looked at this I had no idea what to do, but as I mulled on it did come to me slowly. I didn’t even really know how to use node.js, but I got there and I’m pretty pleased I did.

My solution looks nothing like the codecademy solution, but I’m just happy I got it working. It is here:

Hi everyone,

I completed the FInd Your Hat exercise without the .generateField() for now as I found it quite challenging. You can have a look at my solution here - https://github.com/atanas-dim/find-your-hat/blob/master/main.js

I’ve used nested IF statements for the actual play. I couldn’t come up with anything better at this stage.
Advice and feedback on my use of IF statements are very welcome, as I’m not quite sure if that’s a good practice generally.

Thanks in advance,
Atanas

Hi everyone,

Here is my working solution to this challenge.

My GitHub page also elaborates on where I stumbled and needed more work and what I found helpful. I hope this can help some of you guys out!

Cheers,
Eric

2 Likes

Hi! I just finished my ‘Find your hat’ project. As it was quite a little challenging, it took some time to complete it. Still I really enjoyed doing it. I even took some steps further and extended the project for some extra functionalities. For example I followed the suggesting ideas of:

  • Have the character start on a random location that’s not the upper-left corner.
  • Create a “hard mode” where one or more holes are added after certain turns.
  • Create a field validator to ensure that the field generated by Field.generateField() can actually be solved. This might be pretty difficult!

I’m really proud of what I’ve accomplished so I wanted to share it with you. Any feedback would be gratefull.

Here is my project’s main code.

1 Like

Here is my solution:

I have added:

  • change story from find hat to find hidden chest of gold
  • rename field to map
  • separate player char and path char
  • change chars: player char = smiley, path char = dark field, fall in hole = cross
  • only reveal the field characters around the player when playing
  • allow configuration of map field, hole percentage and field of view
  • ask for player name and use it in game messages
  • count moves to solve map
  • save scores to highscore.txt and display them when winning
  • ask to play again when game is over

Todo:

  • a lot of refactoring :smiley:
1 Like

Hello Guys.
Here is my entry for this project. If anyone have any tips to improve it let me know.

1 Like

Thank you for this. This was by far the most helpful post for me!!! It really helped me understand Codecademy’s solution.

1 Like

Hi,
Below is my solution.

Hello, this is my solution for this project, it was a challenge but I have enjoyed it.

Hey all, here is my project solution. I have so more ideas that I’ve written out in my readme about how I plan to increase functionality of the game as time goes on. Please let me know what you think! wisniewskiz/findYourHat: Codecademy project. (github.com)

Hey,

I enjoyed practising with this project. In the end I added the function that when yhou pick up your hat, you find a puppy underneath it (and in the second level you find 2 extra and so on, hihi) and it will search for you the next time you lose your hat. But the puppies do this very poorly, this could be improved uppon. And the amount of holes is incremental but the program checks if the hat stays reachable or it will draw a new map. Here’s my code :smiley:

Bye,
Marcus