View Single Post
Sitat av Vekst Vis innlegg
ChatGPT ga meg dette svaret når jeg promptet dette.


Of course! Here's a simple web page that meets your requirements. The HTML, CSS, and JavaScript are all kept in the same .html file as you requested:

HTML-kode

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Incrementing Number</title>
    <style>
        /* Simple CSS to center the number on the page */
        body {
            font-family: Arial, sans-serif;
            height: 100vh;
            margin: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: #f4f4f4;
        }
        #numberDisplay {
            font-size: 50px;
        }
    </style>
</head>
<body>

<!-- This is the HTML element that will display our number -->
<div id="numberDisplay">10</div>

<script>
    // Get the numberDisplay element to update its content later
    var numberDisplay = document.getElementById('numberDisplay');

    // Set the initial value of the number
    var numberValue = 10;

    // This function will be called every 60 seconds (60000 milliseconds)
    function incrementNumber() {
        // Increase the numberValue by 1
        numberValue++;

        // Update the content of the numberDisplay element with the new value
        numberDisplay.textContent = numberValue;
    }

    // Call the incrementNumber function every 60 seconds
    setInterval(incrementNumber, 60000);
</script>

</body>
</html>
Instructions:
Copy the entire code block above.
Open your preferred code editor.
Create a new file and paste the code you copied into it.
Save the file with a .html extension, for example, numberIncrementer.html.
Navigate to the location where you saved the file and double-click it. It should open in your default web browser.
You'll see the number 10 displayed. After waiting 60 seconds, the number will increment by 1, and it will continue to do so every 60 seconds.
The code is straightforward: The CSS is used to style and center the number on the page. The JavaScript gets the number display element and sets its initial value to 10. A function (incrementNumber) is defined to increase this number by 1 and update the display every 60 seconds. The setInterval function ensures the incrementNumber function is called every 60 seconds.

Du må gjøre litt matte på setInterval kallet ettersom det er den som bestemmer hvor ofte tallet økes (si ifra om du trenger noe tips her). Og når du skal vise dette frem så trenger du bare oppdatere "numberValue" til tallet du ønsker å starte på hver dag.

Du kan bruke notepad eller notepad++ for å skrive denne .html filen.
Vis hele sitatet...
Tusen takk <3