Jump to content

Halp with HTML Javascript

Beeeyeee
Go to solution Solved by PirateFish,

There's 3 errors in your document.getElementById line.

 

document.getElementById("Story").innerHTML = Hero + " was a spiny little fellow who loved eating" + Food + Hero + " always carried around his " + Item + ". No matter what. It was his favorite! One day" + Hero + " was wlaking by " + Place + ". " + Place + " was a dangerous place where monsters crawled from the abyss" + Hero + " had to cross a river on a " + Thing2 + "the " + Thing2 + "was going crazy, flying across the water. " + Hero + " lost his " + Item + ". He was sad. " + Hero + " cried at the sky. He cursed the " + Thing + ", hr cursed the " + Place + ", and he just wanted some dang " + Food + ". " + Food + ". '" + Hero + " camped out for days. Surviving on scraps of " + Thing + "s to eat. and " + Food + " to take.";

 

I recommend you get an editor with syntax highlighting.

 

working on an assignment for class. I have no idea why this isn't working. f12 console in the browser said theres a syntax error at line 20... but its copypasted from another working assignment... whats wrong?

 

Here's the HTML


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
   <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
   
<head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
        <title>Spiny One</title>
        <link href="Story.Javascript.css" rel="stylesheet" type="text/css" />
    </head>
<body>
    <h1> Legend of the Spiny One<h1>
    <h1 id=Story></h1>
    
    <script type="text/javascript">
    var Hero =prompt("what is your Hero's name?");
    var Item =prompt("a precious possesion");
    var Food =prompt("a food");
    var Thing =prompt("a thing");
    var Place =prompt("a place");
    var Thing2 =prompt("a ricketty thing");
    
    document.getElementById("Story").innerHTML =Hero+" was a spiny little fellow who loved eating"+Food+Hero+ " always carried around his "+Item+ ". No matter what. It was his favorite!""One day"+Hero+ " was wlaking by "+Place+". "+Place+" was a dangerous place where monsters crawled from the abyss"+Hero+" had to cross a river on a "+Thing2;
    "the "+Thing2+"was going crazy, flying across the water. "+Hero+" lost his "+Item+". He was sad. "+Hero+" cried at the sky. He cursed the "+Thing+", hr cursed the "+Place+", and he just wanted some dang "+Food+". "+Food+". '"+Hero+" camped out for days. Surviving on scraps of "+Thing+"s to eat. and "+Food+" to take.;
    </script>
</body>
</html>

 

and heres the Javascript .css stylesheet:


/*
Analogic Color Scheme
Base    Greyed    Bold    Light    Lightest
9EA2BE    7D7F8F    333C7C    C3CC6DF    CACCDF
A89BBD    827B8D    4D337B    CBC1DE    D0C8DE
91A8B2    738086    2F5E74    BBCFD9    C3D2D9
*/

body {
background-color: #9ea2be;
width: 720px;
margin: auto;
}
h1 {
text-align: center;
}

Link to comment
Share on other sites

Link to post
Share on other sites

There's 3 errors in your document.getElementById line.

 

document.getElementById("Story").innerHTML = Hero + " was a spiny little fellow who loved eating" + Food + Hero + " always carried around his " + Item + ". No matter what. It was his favorite! One day" + Hero + " was wlaking by " + Place + ". " + Place + " was a dangerous place where monsters crawled from the abyss" + Hero + " had to cross a river on a " + Thing2 + "the " + Thing2 + "was going crazy, flying across the water. " + Hero + " lost his " + Item + ". He was sad. " + Hero + " cried at the sky. He cursed the " + Thing + ", hr cursed the " + Place + ", and he just wanted some dang " + Food + ". " + Food + ". '" + Hero + " camped out for days. Surviving on scraps of " + Thing + "s to eat. and " + Food + " to take.";

 

I recommend you get an editor with syntax highlighting.

 

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, M.Yurizaki said:

Using JShint also works for linting.

 

Also break up that last line so it's no more than say 100 characters across (80 if you want to keep the old yuppies happy). You can line break after a + and the thing will still be fine.

Okay thanks!

Link to comment
Share on other sites

Link to post
Share on other sites

10 minutes ago, PirateFish said:

There's 3 errors in your document.getElementById line.

 


document.getElementById("Story").innerHTML = Hero + " was a spiny little fellow who loved eating" + Food + Hero + " always carried around his " + Item + ". No matter what. It was his favorite! One day" + Hero + " was wlaking by " + Place + ". " + Place + " was a dangerous place where monsters crawled from the abyss" + Hero + " had to cross a river on a " + Thing2 + "the " + Thing2 + "was going crazy, flying across the water. " + Hero + " lost his " + Item + ". He was sad. " + Hero + " cried at the sky. He cursed the " + Thing + ", hr cursed the " + Place + ", and he just wanted some dang " + Food + ". " + Food + ". '" + Hero + " camped out for days. Surviving on scraps of " + Thing + "s to eat. and " + Food + " to take.";

 

I recommend you get an editor with syntax highlighting.

 

awesome! works fine now! thanks man. I have been using Notepad++ but whats one with sntax highlighting?

Link to comment
Share on other sites

Link to post
Share on other sites

 

1 minute ago, Beeeyeee said:

awesome! works fine now! thanks man. I have been using Notepad++ but whats one with sntax highlighting?

Notepad++ does in fact have syntax highlighting, but it's not the best. I personally use c9.io, an online editor, but you could also use something like Atom.io, which is a desktop IDE by GitHub, or Visual Studio Code by Microsoft, and there are plenty of others.

˙ǝɯᴉʇ ɹnoʎ ƃuᴉʇsɐʍ ǝɹɐ noʎ 'sᴉɥʇ pɐǝɹ oʇ ƃuᴉʎɹʇ ǝɹɐ noʎ ɟI

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×