JavaScript Express Basics Parameters, Query Strings, and Modularizing Routes Randomize Cards

Stephen Powers
Stephen Powers
11,919 Points

Url issues

I understand his solution, but I'm wanted some insight as to why my solution isn't working.

I handled the majority of the logic in Pug, and the only thing not working is when I include the "?" in the code (inlcuded below), everything after it disappears when the request is made. When I omit it, the url renders completely, but without the "?". So I end up with an error because it's not included in the url. What am I missing?

  if side === 'question'
            form(action= `${id}?side=answer` method='get')
              button(type='submit') Answer
  else

              form(action= `${id}?side=question` method='get')
                button(type='submit') Question
Aidan Lowson
Aidan Lowson
8,186 Points

A question mark is a special character in JavaScript try escaping the question mark with a backslash /?

1 Answer

andreavitiani
andreavitiani
10,315 Points

I had the same issue and had to replace the buttons with normal links

if(side === "question")
        h2= prompt
        h2= text
        if hint
            h6
                i Hint: #{hint}
        a(href=id + "?side=answer") Answer
    if(side === "answer")
        h2 The answer is:
        h2= text
        a(href=id + "?side=question") Question