Browser and Web APIs

Chat: Event Handling

  1. Add the following functions to the JavaScript chat:
    • postMessage takes a text and logs it to the console
    • handlePost validates the form, calls the postMessage function with the text of the input field, and clears the form
    Register the handlePost function as an event handler on the Post button.
  2. Create a JavaScript login with the following functions:
    • loginUser and registerUser take a username and password, log them to the console, and navigate to the chat page
    • handleLogin and handleRegister validate the form, call the corresponding user function with the form data, and clear the form
    Register the event handlers on the Login and Register buttons.