#javascript error?

1 messages · Page 1 of 1 (latest)

acoustic sparrow
#

help, does anyone know why this is happening??

fresh mist
#

when you however over it does it tell you anything?

acoustic sparrow
fresh mist
#

try getting rid of the semicolons

acoustic sparrow
#

one sec

#

I can't figure out why the document. write is crossed out

#

:(

fresh mist
#

at least the first error was fixed

#

semicolons in python are weird i dont think they’re required

#

but for the strike through

#

it means that you’re using a function that might be outdated but it still works

#

so you should be fine

acoustic sparrow
#

wait bro

#

I figured it out

#

im dumb asf

#

I put them in html tags

#

it was supposed to be saved as .html

#

i did .js

fresh mist
#

oof idk why i was thinking python 😭

acoustic sparrow
#

what is wrong with this now 😭

fresh mist
#

what is the program attempting to do?

acoustic sparrow
#

just check if an entered year is leap year or naw

#

oh em I got it to work, ty

#

It's working if I run it from the file manager

#

It's not working from live server idk why

#

lol

fresh mist
#

do you have to push the code to it?

#

when i was doing web dev you could run it on vs code and then you had to push it to the server to see it from the link

acoustic sparrow
#

I dunno, I have no idea what "pushing it to the server" mwans 😭

fresh mist
#

did your professor explain anything about how to upload it to the server?

#

which server are you using for it

acoustic sparrow
#

I see this in the file manager

#

double click on it and it runs

#

the js is wrapped in html

fresh mist
#

hmm interesting

acoustic sparrow
#

ye

little leaf
#
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Leap Year Check</title>
</head>
<body>

    <style>
            body {
                background-color: #111;
                display: flex;
                align-items: center;
                justify-content: center;
                height: 100vh;
                overflow: hidden;
            }

            h1 {
                font-family: Arial;
                color: #f4f4f4;
            }
    </style>

  <h1 id="result"></h1>

  <script>
    function isLeapYear(year) {
      if ((year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0)) {
        return true;
      } else {
        return false;
      }
    }

    let year = parseInt(window.prompt('Enter the year:'));

    const result = isLeapYear(year);

    const resultElement = document.getElementById('result');
    if (result) {
      resultElement.textContent = `${year} is a leap year`;
    } else {
      resultElement.textContent = `${year} is not a leap year`;
    }
  </script>
</body>
</html>
#

you were writing quite old js (var keyword, and using .write which is deprecated) so that could have been the problem, you rather want to display the value in html by changing the textContent

#

you also need to specify where you're displaying the content like in my code the result will be written to a h1 identified by its id

#

you'd also ideally rather ask the question in a form instead of using a window prompt as its more user friendly and you can use it faster instead of refreshing each time for the prompt to rerun

magic garden
magic garden
#

For testing purpose use console family command like console.log or consol.table

And for editing text I would recommend query the element and then update it instead of document.Write

acoustic sparrow
#

Thank you very much for this

#

I appretiate you all so much <33

acoustic sparrow
acoustic sparrow