This is a read-only archive. No new posts or registrations. Privacy Page
Software

Implementing a While Loop using Javascript for a Website

1 min read

This thread's last reply is from . Advice, software, and links below may be out of date — treat specific steps and download links with caution.

Looking for the outcome? Ask AI

Hey there,

I am wondering if anyone knows how to, or can give me an example of a while loop that I can use for a website.

Looking online, I can;t seem to find any useful while loops that can be implemented into my website. I can't seem to think of any logical ones either apart from this one:

What I'm trying to do is when someone comes onto my website, I want them to be prompted using window.alert stating "Are you sure you want to enter this website? Please enter "Yes" to enter or "No" to leave the page. if they choose yes it will go to my Home.html page and if they choose "No" it will either return them to their homepage or to Google.

Does anyone know how to do this? I know it isn't the best While loop out there, but really it's just for show for a project. Please help if you can.

Note: It has to be a While loop. I do know how while loops work I'm just really having trouble implementing one to a website.
I wish I knew more about Javascript to help you.

I did research this a little bit. According to these links:
http://www.sbrady.com/hotsource/javascript/popup.html
http://www.javascriptkit.com/javatutors/alert2.shtml

The method for requesting if a user wants to enter a page is with a confirm, not an alert. And the response is handled in a simple if statement.

I don't see how you are going to provide a yes/no option with a windows.alert. And, if you use window.confirm, then there is no reason for a loop. From what I can see there would be absolutely no reason to justify trying to use a loop in this situation. Can you tell why it must have the loop? Maybe there is another way of looking at things.

Ask AI

AI can make mistakes. Check the cited posts. Archived advice can be out-of-date

Don't include personal information. Questions and selected public posts go to OpenAI. About Ask AI