Skip to content

Instantly share code, notes, and snippets.

@kyletolle
Last active May 30, 2024 20:31
Show Gist options
  • Save kyletolle/a9c4e3eb0fc95a140f330dcbac1195c6 to your computer and use it in GitHub Desktop.
Save kyletolle/a9c4e3eb0fc95a140f330dcbac1195c6 to your computer and use it in GitHub Desktop.
Some simple HTML pages to share with Maisie
<!DOCTYPE html>
<html>
<head>
<title>Change Text Example</title>
</head>
<body>
<h1>Change Text with JavaScript</h1>
<p id="myParagraph">This is the original text.</p>
<button onclick="changeText()">Change Text</button>
<button onclick="fooblap()">Button without a Function!</button>
<script>
function changeText() {
document.getElementById("myParagraph").innerText = "The text has been changed!";
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>My First Web Page</title>
</head>
<body>
<h1>Welcome to My Web Page</h1>
<p>This is a paragraph of text.</p>
<input type="number" id="myNumber" value="0">
<button onclick="doubleTheNumber()">Double the Number!</button>
<script>
function doubleTheNumber() {
const numberElement = document.getElementById("myNumber")
const userNumber = numberElement.value;
const doubledValue = userNumber * 2;
alert(`The double of ${userNumber} is ${doubledValue}`);
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>My First Web Page</title>
</head>
<body>
<h1>Welcome to My Web Page</h1>
<p>This is a paragraph of text.</p>
<button onclick="sayHello()">Click me!</button>
<script>
function sayHello() {
alert("Hello, World!");
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Simple Calculator</title>
</head>
<body>
<h1>Simple Calculator</h1>
<input id="num1" placeholder="Enter first number">
<input type="number" id="num2" placeholder="Enter second number">
<button onclick="calculate()">Calculate</button>
<p id="result"></p>
<script>
function calculate() {
let num1 = parseFloat(document.getElementById("num1").value);
num1 = isNaN(num1) ? 0 : num1;
num1 = Math.round(num1);
let num2 = parseFloat(document.getElementById("num2").value);
num2 = isNaN(num2) ? 0 : num2;
num2 = Math.round(num2);
const result = num1 + num2;
document.getElementById("result").innerText = "Result " + result;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment