I just bought the same (or a very similar) laptop and have the same issue. I have to be right on top of the router to get it to reliably connect to wifi and even in this case it's some times only getting a poor connection. If I move away from the router it dies. I am working from someone at HP tech support, and they have done everything they can do, and we are now re-installing the OS.
Be alert for scammers posting fake support phone numbers and/or email addresses on the community. If you think you have received a fake HP Support message, please report it to us by clicking on "Flag Post".