Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Dec 2013
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Post Need help with school assignment!

    Today i got an assignment, and for it I chose to write lines of code and make a game. But the only problem is that i new to coding, and I thought that I would make, a choose your way, type of game with 3 endings. So I was wondering if any could please write a small code, or explain how to make a choose your way type of game, or can you talk to me on skype. message my and tell me your skype name or ill give you mine. Thank you, and ill appreciate any help and also I'm grade 8

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,308
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    This forum is not a free coding service. As a general rule, the people helping out in this forum don't write code for others (especially code that appears to be for homework), but try to help with fixing code that doesn't work. You'll be far more likely to get help if you have made a substantial effort and written some code yourself. Then someone here will almost certainly help you correct/improve your work.


    The UK is stuck in the Middle Ages, and only wants to use nuclear power. - Caller, BBC Radio Five Live

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,634 Times in 4,596 Posts
    Advice: Start by writing out a *COMPLETE* description of how the game is played, including ALL possible endings. Write it in English (or whatever if you native language), *NOT* in code.

    Post that, here, for a critique of the game.

    *THEN*--and only then--can you start translating from human to JavaScript language.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,146
    Thanks
    39
    Thanked 505 Times in 499 Posts
    Here is a starting template for most JS coding...
    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    
    <meta name="viewport" content="width=device-width">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=yes"/>
    <title> HTML5 page </title>
    
    <style type="text/css">
    @media print { body { font-size: 16pt } }
    @media screen { body { font-size: 18px } }
    @media screen, print { body { line-height: 1.2 } }
    
    </style>
    
    <script type="text/javascript">
    
    </script>
    </head>
    <body>
    
    <script type="text/javascript">
    
    </script>
    </body>
    </html>
    Note the use of the [ code] and [ /code] tags (without the spaces) to highlight your attempts
    for other forum members to review.

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by jmrker View Post
    Here is a starting template for most JS coding...
    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    
    <meta name="viewport" content="width=device-width">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=yes"/>
    <title> HTML5 page </title>
    
    <style type="text/css">
    @media print { body { font-size: 16pt } }
    @media screen { body { font-size: 18px } }
    @media screen, print { body { line-height: 1.2 } }
    
    </style>
    
    <script type="text/javascript">
    
    </script>
    </head>
    <body>
    
    <script type="text/javascript">
    
    </script>
    </body>
    </html>
    Note the use of the [ code] and [ /code] tags (without the spaces) to highlight your attempts
    for other forum members to review.
    You don't need the script tag in the head - there are only two scripts that need to go in the head - the billions of others can all go at the bottom of the body.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,146
    Thanks
    39
    Thanked 505 Times in 499 Posts

    Exclamation

    Quote Originally Posted by felgall View Post
    You don't need the script tag in the head - there are only two scripts that need to go in the head - the billions of others can all go at the bottom of the body.
    What are the two that need to go in the <head>? External libraries?
    I can think of more that can optionally go there, but need?
    Even the external files can be called after the <body> tag optionally.

    Anyway, as a template, the user can remove 3 lines if not used,
    or the script will be ignored if nothing is between the tags.

    Still more code than provided in post #1

    Edit: Afterthought...
    Should have also have added to the template the command for external CSS file links

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,308
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Here is something on which felgall and I are in complete agreement:- ALL scripts belong at the bottom of the body with only two exceptions - a framebreaker script and one that adds a class to the html tag.

    Scripts in the <head> may work, but may well refer to elements which do not exist yet, and so require to be run onload.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by jmrker View Post
    What are the two that need to go in the <head>? External libraries?
    I can think of more that can optionally go there, but need?
    Even the external files can be called after the <body> tag optionally.
    Any script can optionally go in the head if you wrap it inside a load event listener so that it can't run before the page loads.

    Any library script reference can go at the bottom of the body immediately before your custom script.

    The only two scripts that need to go in the head are the two I mentioned (there are of course a number of variants in how these cal be written but the following are the simplest versions:

    if (top.location !== self.location) top.location = self.location;

    and

    document.getElementsByTagName('html')[0].class += ' js';

    The first of these is a framebreaker script that reloads the page before it displays if an attempt is made to load the page in a frame. Any other script that reloads the same or a different page without displaying the current page first is a variant of this script. Because the current page is NOT to be displayed first this script needs to go in the head.

    The second of these is the modern replacement for the <noscript> tag. Simply by adding .js to the front of styles in your stylesheet you can style the page completely differently for when JavaScript is enabled to how it looks without JavaScript. Some variants on this script (eg. modernizr.js) make additional tests so as to add a number of classes to the html tag to indicate what the current browser does and doesn't support so that the page can be styled differently depending on which parts of JavaScript are and are not supported. Because you want the page styled from the start based on whether this class has or hasn't been added this script needs to go in the head.

    With both of these but with no other script that I know of the script only works correctly if placed in the head. If you place either of these anywhere else in the page then the page will display incorrectly first and only fix itself when the script runs.

    I am not claiming that these are the only two scripts that need to go in the head but I have never come across any others that are not just variants on one of these two. If you know of a third example of a script that needs to go in the head that is not a variant of one of these two scripts please let us know.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #9
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,146
    Thanks
    39
    Thanked 505 Times in 499 Posts

    Arrow

    Originally Posted by jmrker:
    What are the two that need to go in the <head>? External libraries?
    I can think of more that can optionally go there, but need?
    Even the external files can be called after the <body> tag optionally.
    Quote Originally Posted by felgall View Post
    ...
    I am not claiming that these are the only two scripts that need to go in the head but I have never come across any others that are not just variants on one of these two. If you know of a third example of a script that needs to go in the head that is not a variant of one of these two scripts please let us know.
    I was asking a question, not making a statement.
    You seem to have adequately provided a response.


  •  

    LinkBacks (?)


    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •