Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
I have written a HTML code, but it is not working.What may be the reason?
Here is the code:-
<HTML>
<HEAD>
<TITLE>Sachin Rox</TITLE>
<SCRIPT LANGUAGE="JavaScript">
var number1, number2, sum;
number1 = window.prompt ("Enter first number", "0");
number2 = window.prompt ("Enter second number", "0");
sum = parseInt(number1) + parseInt(number2);
document.writeIn("<H1> <FONT FACE="MONOTYPE CORSIVA">The sum is " + sum + " </FONT> </H1>");
</SCRIPT>
</HEAD>
</HTML>
I will be extremely thankful to anyone who finds an error in this or tell me a reason why it isn't working.Also, I think just executing a document with the following code in a browser like say, Internet Explorer7 or Google Chrome should do it.Or is some special interpreter software needed?
4 Answers
- Anonymous1 decade agoFavorite Answer
You don't have a <body> tag.
You put the JavaScript in, but you never actually call the script anywhere. Just adding the script code to the file doesn't do anything. Something in the script has to activate it, like clicking on something.
Stop using UPPER CASE in your tags. This is no longer an acceptable style. The current XHTML standard requires all tags to be in lower case.
Stop using the FONT tag. It's been depreciated. Use style sheets instead. Not every system has the monotype corsiva font.
You don't need any kind of interpreter. This is HTML and JavaScript. All browsers have this built into their engines.
I strongly recommend you read through some of the tutorials in the link below.
Source(s): http://www.w3schools.com/default.asp - Anonymous5 years ago
I don't know why you need three reasons. The main reason is that by knowing HTML you are not dependent on a particular tool.
- Tizio 008Lv 71 decade ago
your script is executed inside the head tag and would produce html output, that is an error.
after the closing head tag, you must add the body tag, which is the tag where the "text" content of an html is.
<body>
content
</body>
then you must move your script in stead of content, say, and you should see the right behaviour :D
you don't need special interpreter :) common browser can run javascript... and since you're producing html code, you need a browser. microsoft has a jscript, that is basically javascript, that can run as script outside any browser... but then the document object does not exist of course.
another error i notice now... it should be "write", no "writeln" as far as i remember ... another error... you do not escape the " inside the string, ... you must write
\"MONOTYPE CORSIVA\"
and oh... i am going to criticise minor points... prefer lowercase tag... (if you plan to go into xhtml, you will appreciate the habit) ... do not pretend the average user to have the "monotype corsiva" font, your page can look different on different machine, depending if the font exists or not on that machine... write alternative fonts, and end with a generic specification like "serif"...
- AnalProgrammerLv 71 decade ago
The problem has nothing to do with the mising BODY tag though that is not proper HTML.
The problem is in your writeln command
You cannot use double quotes for more that one purpose. you should either escape the double quotes or mix them up like
document.writeln('<H1> <FONT FACE="MONOTYPE CORSIVA">The sum is ' + sum + ' </FONT> </H1>');
Have fun.