...

View Full Version : Resolved Help! What is wrong with this code?? (Variables and Strings)



MancunianMacca
02-28-2012, 08:17 PM
<html>
<head>
<title> Caught </title>

<script language="JavaScript">
<-- hide me

// get user to add name

var name_entry = prompt ("Please Enter your Name!", "James");

// declare some short strings

var stating = ", I knew you did it!"
var told = "I told you that I would find out"
var mistake = "I guess you just made a mistake entering your name,"
var punish = "Now go back to your room"

// construct some longer strings

var stating_name = name_entry + stating;
var mistake_name = mistake + name_entry;

// stop hiding me -->
</script></head><body>

<h1> OI Stop! </h1>

<script language="JavaScript">
<!-- hide me

document.writeln(stating_name + "<br>");
document.writeln(told = "<br>");
document.writeln(mistake_name = "<br>");
document.writeln(punish = "<br>");

// show me -->
</script>
</head>
<p>
<FORM>
<INPUT TYPE="button" VALUE="To Your Room" onClick="history.back()">
</FORM>

</p>
</body></html>


It will not show my strings and variables?? Please Help!!

Philip M
02-28-2012, 08:51 PM
You should use your error console to reveal numerous errors.


<html>
<head>
<title> Caught </title>


<script type = "text/javascript">

// get user to add name

var name_entry = prompt ("Please Enter your Name!", "James");

// declare some short strings

var stating = ", I knew you did it!";
var told = "I told you that I would find out";
var mistake = "I guess you just made a mistake entering your name,";
var punish = "Now go back to your room";

// construct some longer strings

var stating_name = name_entry + stating;
var mistake_name = mistake + name_entry;

document.writeln(stating_name + "<br>");
document.writeln(told + "<br>");
document.writeln(mistake_name + "<br>");
document.writeln(punish + "<br>");

</script>

</head><body>

<h1> OI Stop! </h1>

</body></html>

<script language=javascript> is long deprecated and obsolete. Use <script type = "text/javascript">. The <!-- and //--> comment (hiding) tags have not been necessary since IE3 (i.e. since September 1997). If you see these in some published script it is a warning that you are looking at ancient and perhaps unreliable code.

document.write statements must be run before the page finishes loading. Any document.write statement that runs after the page finishes loading will create a new page and overwrite all of the content of the current page (including the Javascript which called it). So document.write is at best really only useful to write the original content of your page. It cannot be used to update the content of your page after that page has loaded.


Bookshop Assistant: "This book about Javascript will save you half your work".
Lazy Student: "Oh good! I'll take two!"



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum