I cant find a good solution for my fist java script class. Can someone help me here. The result is not showing up here.

<script language = "JavaScript">
document.write('<center><h3>-- Myname 23 -- ')
myDate = new Date ();
document.write(myDate.toLocaleString());
document.write('</h3></center><hr>');

</script>

<script language = "JavaScript">

// Add, subtract, multiply, and divide
var firstvar;
var secondvar;
var resultvar;

// Add 23.5 and 15

document.write ('adding 23.5 and 15

');
firstvar=23.5;
secondvar=15;
resultvar

document.write(firstvar);
document.write('
');

document.write(secondvar);
document.write('
');

document write('---');
document.write('
');

resultvar = firstvar + secondvar;
document.write(resultvar);
document.write('

');

// Subtract 45 from 10

document.write ('subtracting 45 from 10

');
firstvar=10;
secondvar=45;

document.write(firstvar);
document.write('
');

document.write(secondvar);
document.write('
');

document.write('---');
document.write('
');

resultvar= firstvar - secondvar;
document.write(resultvar);
document.write('

')

// Multiply 2.5 by 15

document.write ('multiplying 2.5 by 15

')
firstvar=2.5
secondvar=15

document.write(firstvar);
document.write('
');

document.write(secondvar);
document.write('
');

document.write('---');
document.write('
');

resultvar= firstvar * secondvar;
document.write(resultvar);
document.write('

');

// Divide 144 by 12

document.write ('dividing 144 by 12

');
firstvar=144;
secondvar=12;

document.write(firstvar);
document.write('
');

document.write(secondvar);
document.write('
');

document.write('---');
document.write('
');

resultvar= firstvar / secondvar;
document.write(resultvar);
document.write('

');
</script>

I'm sorry, but this ia a Java forum. JavaScript != Java. Please get this moved to a JavaScript forum.

Aneone here who can help me out on this problem?

This is the HTML, CSS, and JavaScript forum.

How are you calling the JavaScript from your html code? It doesn't just run itself.

Either your main JavaScript code must be in the body portion of the code, or you must use an on-action attribute in an html tag to cause a function to be called when the specified action occurs.


Also, I see some errors in your code. Errors cause the JavaScript interpreter to quit running.

The errors:

Line 1: The language attribute is nonstandard. Use type="text/javascript" instead.

Line 2: Missing ending ;

Lines 7-9: Only one main program is allowed in an html file. Which set runs depends on the browser.

Line 18: Incomplete statement (you can't start a quote on one line and end it on another - note that if the listing program you used to put this page here is rendering \n as a real newline instead of printing the characters, these are not errors).

This also happens in lines:
23, 26, 30, 34, 39, 45, 52, 56, 60, 65, 71, 78, 82, 86, 91, 97, 104, 108, 112, and 117.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.