I understand you're unable to join a wireless network, and are probably getting a dialog box that says something like "unable to join the network <name>" after selecting the wireless network and providing its password. Is that correct?
Read If your Mac doesn't connect to the Internet over Wi-Fi.
If none of that helps, try the following. It will help determine whether the problem is with macOS, the MacBook's Wi-Fi hardware, or something else.
- Shut down your Mac.
- Load macOS Recovery by holding ⌘ and r (two fingers) while you start your Mac with a third finger.
- At the macOS Utilities screen, release those two fingers.
Determine if you can join the Wi-Fi network while in Recovery mode. If you are able to successfully join the network, choose Get Help Online from the macOS Utilities screen.
- You should be able to load Safari webpages as you normally would.
- If you are still unable to load webpages, then quit Safari and choose Reinstall macOS.
Reinstalling macOS is nondestructive to your User Account data, but you ought to create a Time Machine backup as a matter of course. To learn how to use Time Machine please read Back up your files with Time Machine on Mac.