Hello, there!
I am making a vector cross product calculator. I do it with JavaScript and show it in HTML.
I have made the converter work, but when I want my small program show me the result using document.write(), it deletes the previous page while pasting the result. How do I get JavaScript paste in a line without deleting the whole page?
I know that I could use alert(), but it didn't look so nice.
Remember that I am an absolute beginner, so no advanced commands, please.
Here is the calculator.
My script:
Thank you for your time.
I am making a vector cross product calculator. I do it with JavaScript and show it in HTML.
I have made the converter work, but when I want my small program show me the result using document.write(), it deletes the previous page while pasting the result. How do I get JavaScript paste in a line without deleting the whole page?
I know that I could use alert(), but it didn't look so nice.
Remember that I am an absolute beginner, so no advanced commands, please.
Here is the calculator.
My script:
HTML:
<!DOCTYPE hmtl>
<html>
<head>
<title>Cross product.</title>
</head>
<body style="background-color:#E4E4E4; font-family:Calibri; color:#271828">
<h1>Cross product!</h1>
<!-- Some Norwegian text without importance -->
<p>
Hei! Dette er en vektorkryssproduktkalkulator. Akkurat som navnet antyder krysser den vektorer for å finne vektorkryssproduktet. Prøv det ut!
</p>
<script>
function cross()
{
// Type vector nr.1
var x1 = prompt("Type x-value for vector nr.1.");
var y1 = prompt("Type y-value for vector nr.1.");
var z1 = prompt("Type z-value for vector nr.1.");
document.writeln("Vector nr. 1 is [" + x1 + ", " + y1 + ", " + z1 + "]. ");
// Type vector nr.2
var x2 = prompt("Type x-value for vector nr.2.")
var y2 = prompt("Type y-value for vector nr.2.")
var z2 = prompt("Type z-value for vector nr.2.")
document.writeln(""Vector nr. 2 is [" + x2 + ", " + y2 + ", " + z2 + "]. ");
// Crossing two and two values
var crossx1 = y1 * z2
var crossx2 = z1 * y2
var crossy1 = z1 * x2
var crossy2 = x1 * z2
var crossz1 = x1 * y2
var crossz2 = y1 * x2
// Subtract and find x, y and z.
var x = crossx1 - crossx2
var y = crossy1 - crossy2
var z = crossz1 - crossz2
// The resulting cross product.
var vector = "[" + x + ", " + y + ", " + z + "]"
// Print the result
document.writeln("Your vector cross product became " + vector + ".");
}
</script>
<p> </p>
<button type="button" onclick="cross();">Calculate!</button>
<p> </p>
<!-- Refresh button for when it wasn't a function, but ran at page opening, so not necessary now -->
<button type="button" onclick="history.go(0)">New cross product. Will remove previous calculations!</button>
</body>
</html>
Thank you for your time.