The logic was correct and there were no problems or warnings when I uploaded the code but it wasn't compiled. I also followed the instructions and clicked the boot button while uploading it was displaying "upload failed" I tried but the code wasn't uploaded to ESP32.
You should check if esptool.exe is accessible via your command prompt.
Steps to check that: