Loop Iteration in Php Game

后端 未结 5 1613
被撕碎了的回忆
被撕碎了的回忆 2021-01-28 23:37

Trying to get it to loop through 3 times and after the 3rd time (if not guessed right) show the right answer.

Currently - its going through the guesses, but isnt showing

5条回答
  •  萌比男神i
    2021-01-29 00:23

    the return statement is leaving the loop and the script

    get rid of both return statements

    DC

    Further to your comments on the duplicate question at... Allowing 3 attempts at game - php

    It would appear that this question is a 'homework' question as such and in fact with all questions no-one will give you the complete answer, nor in my opinion should they. We all expect that the person asking the question will take it upon themselves to investigate and understand the answers given.

    Now in the case of your question, you appear to be missing a vital piece of information about how HTTP works (http is the protocol that drives all web pages and many other parts of the internet).

    http is what's considered a stateless protocol, that is when you click on a link in a web page and go to another web page (or even the same web page), the new web page considers you a totally new visitor. It in effect has forgotten you.

    Because this introduced issues for things like shopping carts (and PHP games) cookies were invented. this allowed the browser to carry around a small bit of information about you, in this way the web server or application remembered you. This has been extended into what respondents here are calling sessions.

    A session is (usually) a cookie that stores an identifier. that identifier tells, in this case PHP, that you have been there before and where to find the information about you. PHP can load this information and make it available to you the programmer.

    This happens EVERY TIME a page is loaded.

    Now PHP does not know what to store in this 'session' it is up to you the programmer to decide what information needs to be stored. you need to tell PHP to save this information for the next time the page is loaded.

    In your case its up to you to decide what needs to be remembered. Consider the reloading of the page to be a new 'iteration' of the loop. this should lead you to some obvious conclusions about what needs to be passed from one iteration to the next.

    There you go. I haven't written the answer for you but hopefully have provided enough for you to pass your class in flying colours.

    DC

提交回复
热议问题