#javascript error?
1 messages · Page 1 of 1 (latest)
when you however over it does it tell you anything?
this
try getting rid of the semicolons
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
js js
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

oof idk why i was thinking python 😭
what is wrong with this now 😭
what is the program attempting to do?
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
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
I see
I dunno, I have no idea what "pushing it to the server" mwans 😭
did your professor explain anything about how to upload it to the server?
which server are you using for it
nop
im not? 😭
I see this in the file manager
double click on it and it runs
the js is wrapped in html
hmm interesting
ye
<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>
result
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
If you are learning then I would suggest you not to use document.write as it is deprecated and some pitfalls
More info:
https://developer.mozilla.org/en-US/docs/Web/API/Document/write
There is a vscode extension "live server" which can be used to view your code directly through a server setup. If you are already using it (guessing from 5500 port) you need to restart the server
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
I seee
Thank you very much for this
I appretiate you all so much <33
yesh I have it installed :)
oh the question tells us to use the prompt