‘Uncaught ReferenceError: window is not defined’ in vanilla javascript

I have come across this reference error (Uncaught ReferenceError: window is not defined) when trying to build a weather app using just html/css/js. I have looked up and tried several solutions from here and elsewhere but nothing seems to solve my issue. Any help would be appreciated.


 <!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./styles.css">
  <div class= "location">
  <h1 class=location-timezone>Timezone</h1>
<div class="temperature">
    <div class="degree-section">
    <h2 class="temperature-degree">34</h2>
    <div class="temperature-description">It's cold


    window.addEventListener("load", () => {
    let long;
    let lat;

    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(position => {
    } else {
        h1.textcontent = "Please allow permission."

Read more here: https://stackoverflow.com/questions/65711496/uncaught-referenceerror-window-is-not-defined-in-vanilla-javascript

Content Attribution

This content was originally published by Mamdlv at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: