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

Stephen Powers
Stephen Powers
12,078 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

              form(action= `${id}?side=question` method='get')
                button(type='submit') Question

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

1 Answer

13,313 Points

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

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