Giter Club home page Giter Club logo

egroene / hogwarts-house-quiz Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 7.24 MB

Brief quiz that places user in one of four categories based on answers to weighted questions. I made this to practice DOM manipulation & other JS skills.

Home Page: https://whats-my-hogwarts-house.netlify.app/

HTML 3.12% JavaScript 37.94% CSS 15.17% TypeScript 43.77%
javascript css css-animations css-flexbox html html-css-javascript javascript-development javascript-dom javascript-game javascript-objects javascript-vanilla harry-potter hogwarts typescript javascript-games typescript-game

hogwarts-house-quiz's Introduction

hogwarts-house-quiz

As the name suggests, this web app, which I built using HTML, CSS, & vanilla TypeScript, gives users the chance to see which Hogwarts House they would likely be sorted into. Below, I describe how it works. For more details, please see my code and the comments within.

  • A random image displays as the page background. I stored several image URLs from Unsplash in an array & looped through it, selecting a random one when the page loads & when a new question displays. I set a particular background on the results page.

  • Upon loading of the page, the user is greeted & prompted to click a button to start the quiz, whether they want to play the shorter (15 questions) or the longer version (30 questions).

  • Upon starting the quiz, the greeting is hidden & the first question displays. For each question, I display the question tally out of total questions, which I store as objects inside of an array, so it displays as: index of the question / length of questions array, which is also randomized, except for the last question of the quiz, which asks the user for their house preference. When the user plays the shorter version, a random 14 questions not about their house preference are selected and added to the questions array. Whether the short or the long version is played, the question about their preference is appended to the questions array.

  • The question itself, which is a property of the given question's object inside the array containing all the questions, displays under the tally. Answer options are randomly ordered.

  • Inside each question's object, I also added a 'weight' property, which is a number indicating the importance of the question in determining the user's house. When the user selects an option, this 'weight' property is added to the point total for the corresponding house, which are stored in an array.

  • Upon moving to the next question (which happens immediately when the user selects a question option, the info for that question is cleared from the DOM, and, if there is a sequential question, the info for that question populates the DOM; if there is no question to follow, the questions area is removed from the DOM & the results area displays.

  • At the end of the quiz, the house with the highest point total is selected & its corresponding crest & heading appears. For this, I added a couple of cool animations.

If you are curious to try it out for yourself, go here: https://whats-my-hogwarts-house.netlify.app/

I am happy to hear any feedback, whether it's on the experience of using this app, or on my code. Thanks for reading!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.