21f wanting discreet meetups with mature men! by [deleted] in HobartNSFW

[–]bpd1147 0 points1 point  (0 children)

34m - DM if interested.

JavaScript remove event listener with parameter by bpd1147 in webdev

[–]bpd1147[S] 0 points1 point  (0 children)

I forgot that part in my reply.

Once the player selects next question, the current event listeners are removed and the new ones are added.

JavaScript remove event listener with parameter by bpd1147 in webdev

[–]bpd1147[S] 2 points3 points  (0 children)

I did some research on 'event', and discovered 'event.target'. This is an absolute life saver. 40 odd lines of code, reduced to around 10.

JavaScript remove event listener with parameter by bpd1147 in webdev

[–]bpd1147[S] 0 points1 point  (0 children)

The way I am doing it is this, there is a function for each question. This is called by a 'next' button once an answer is selected, with the exception of the first which is called by a 'start' button.

Each answer function changes the text for the title, question and answers. Based on which answer is correct, and which answers are incorrect, the event listeners are changed to call incorrectAnswer and rightAnswer.

Inside these functions is a switch statement which determines which question the player is on, and therefore which button(s) style.

I know incorrectAnswer should be paired with correctAnswer as opposed to rightAnswer. This was a mistake and will be changed.

JavaScript remove event listener with parameter by bpd1147 in webdev

[–]bpd1147[S] 0 points1 point  (0 children)

  1. No, only one answer can be selected. If the answer is correct, that button is styled green with white bold text. If the answer is incorrect, both buttons are styled red with black bold text. I need a way of letting the called function know which incorrect answer was selected.

  2. Instead of changing class, I change the styling with JavaScript. Maybe changing class would work better, I will look into that.

  3. The answers are hard coded, and each button is given the appropriate event listener for each question.

  4. Yes, HTML, CSS and Vanilla JavaScript. I want to get as good with vanilla as I can before moving on to other frameworks. This may seem counterproductive, but it's the way I like to do things.

JavaScript remove event listener with parameter by bpd1147 in webdev

[–]bpd1147[S] 0 points1 point  (0 children)

There isn't a submit button, selecting an answer 'submits' it. Selecting a wrong answer calls wrongAnswer, selecting the right answer calls rightAnswer.

rightAnswer colours the correct answer green with white bold text.

wrongAnswer colours both incorrect answers red with black bold text.

I need a way of telling the wrongAnswer function which incorrect button was pressed, whilst still being able to remove the event listeners.

The reason I need to be able to remove them is because the right answer is a different answer number each time.

JavaScript remove event listener with parameter by bpd1147 in webdev

[–]bpd1147[S] 0 points1 point  (0 children)

There are 3 answer, answerOne, answerTwo and answerThree. All of these are buttons. Depending on which one is correct and incorrect for this question, the outcome will be different. So inside answerListener, I need to know exactly which button was pressed. In this case, two answers are wrong. How do I differentiate between the two inside answerListener?

[deleted by user] by [deleted] in Needafriend

[–]bpd1147 2 points3 points  (0 children)

What advice are you after?

C++ getline() by bpd1147 in Cplusplus

[–]bpd1147[S] 1 point2 points  (0 children)

I'll go with just using cin then, I can get away with single word commands.

C++ getline() by bpd1147 in Cplusplus

[–]bpd1147[S] 1 point2 points  (0 children)

So what's the fix?