Trouble linking HTML, Javascript, and CSS - seeking help to get them working properly

Hey there! I'm currently trying to transfer my project from Codepen at here to repl.it (This project) which you can find at this link. Don't forget to click run after checking it out!

The code is working perfectly fine on Brackets with the same code from Codepen. So, why isn't it working on repl.it?

Here are some issues that have appeared:

  1. The CSS and JavaScript aren't loading properly. I tried using
    <script src="index.js"></script>
  2. Could it be that the CSS isn't linked correctly? I'm used to only using Codepen so I'm not familiar with linking between CSS, HTML, and JS.
  3. I seem to have typed 2 before 1. Whoops!
  4. The HTML does not seem to be flexible (like Bootstrap), so if it works, it won't be responsive.

Check out all the links and codes below - any clarification would be greatly appreciated:

<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>Your local weather</title>


<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.min.css'>
<link rel="stylesheet" href="css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="index.js"></script>


</head>

I really need help with this. I apologize for coming across as a newbie, but we all start somewhere. This area of coding is new to me, especially when compared to HTML. Any guidance is welcomed!

I didn't include a JavaScript tag because everything seemed fine on Codepen. Could it be that API's don't work on repl.it?

    // Line 10
navigator.geolocation.getCurrentPosition(function(position) {
          lon = position.coords.longitude;
          lat = position.coords.latitude;
          var api =
            "https://fcc-weather-api.glitch.me/api/current?lat=" +
            lat +
            "&lon=" +
            lon;
          $.getJSON(api, function(data) {

Answer №1

Your mistake was editing the HTML page within repl.it.

  1. You made a big mistake by placing both the script tag in the head and body for adding an external JavaScript file. You should remove the script from the head.
  2. repl.it doesn't recognize href="css/style.css". This is your major error. Verify where you have written the CSS code. Your custom CSS file is named index.css, not style.css. There are no absolute file paths in repl.it like css/style.css. If you add a new CSS file called custom.css, it should be referenced as href="custom.css".

I have created a new snippet for you on repl.it; please check and compare.

According to comments by user9319687, there seems to be an issue with JavaScript not running. However, this is incorrect as JavaScript is functioning properly. The script might not run because Google GEO Location services require an HTTPS server. You can check by opening this link and going to the console.

[Deprecation] getCurrentPosition() and watchPosition() no longer work on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See here for more details.

For more information on the HTTPS and HTTP issue, refer to StackOverflow and Github.

  • Solution 1: Run this project on an HTTPS server for it to work.
  • Solution 2: Run the project on a localhost server for functionality.

If wondering how codepen.io runs scripts, it's because they operate on an HTTPS server.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Create a duplicate of the table and remove specific rows

Hi there, I have a query about duplicating a table. I am looking to extract specific results and display only those results. To illustrate, here is an example in HTML code: <table class="table table-striped" id="ProfileList2"> <tbody> ...

Instructions for creating a JavaScript click function that iterates through all records, not just the initial record

Although I'm new to web development and still learning the basics of html, javascript, etc., I have a problem that seems quite simple. The challenge lies in understanding javascript functions, which I find particularly tough to grasp. Here's what ...

Beautiful forms leading to unambiguous form problem

Does anyone know why, on my form, clearing the fields resets the dropdown values to '', but does not display the actual option text? Any insights? $(':input','#templatesForm') .not(':submit, :button, :hidden, :reset&apos ...

Conceal objects in reverse sequence

My goal is to clear notifications grouped on a mobile OS style interface when clicking the "X" button. They should be removed in reverse order with a 1-second delay between each. Here's what I've achieved so far: $(document).ready(function () { ...

Arranging date and time in jQuery based on AM/PM notation

I have written some JavaScript code to sort dates in ascending order (from newest to oldest). I have successfully sorted the dates, but I am having trouble sorting the time with AM or PM using a 12-hour format. I can do it in a 24-hour format, but not in ...

Changing the z-index using createjs

Is there a way to ensure that the dragged item always stays on top when moved? How can I prevent it from getting dragged underneath another object? Can I specify which "sequenceNumbers" should be moved to the top of the sorting order? //++++++++ ...

Issues with implementation of map and swiper carousel functionality in JavaScript

I am trying to populate a Swiper slider carousel with images from an array of objects. However, when I use map in the fetch to generate the HTML img tag with the image data, it is not behaving as expected. All the images are displaying in the first div a ...

What is the purpose of text-indent when using image replacement techniques?

I've implemented the code below for my primary menu a links: #sliding-navigation #filter-regista a { width: 75px; height: 29px; background: transparent url("images/directors.png") no-repeat 0 0; text-indent: -9999px; } Appreciate any ...

JavaScript and HTML code for clipboard functionality without the need for Flash

My challenge lies in creating a grid with numerous columns and data. The user has expressed the desire for a copy to clipboard button that will allow them to easily copy the data. Can anyone suggest ways to implement Copy to Clipboard functionality withou ...

What is the regular expression that allows numbers between 1 and 24, including decimals?

Can anyone help me create a regex expression that only allows numbers between 1 and 24, with up to 2 decimal places? The numbers should range from 1 to 24, as well as include decimals like 1.00, 1.01, 1.02, all the way up to 24.99. ...

Saving user-generated inputs within a React.js component's state, focusing on securely handling passwords

Curious about forms in React.js? I don't have any issues, but I'm wondering if there are potential flaws in my approach. I've set up a basic form with two inputs for email and password: <input type="email" name="email" value= ...

Unlocking the res property in index.js from an HTML script tag: A step-by-step guide

Can anyone help me with the access variable issue I am facing? I have two files, index.js and page.ejs. These files require me to create a timer linked with datetimes stored on my local server. //index.js.. router.get('/mieiNoleggi', functio ...

Encountering an issue while attempting to extract an ACF field in WordPress using JavaScript

When I write the following code, everything works fine: <script> $(document).ready(function(){ var user_id = '<?php echo get_current_user_id(); ?>'; // This is working var subject = "<?php echo the_field('subject ...

Personalize scrollbar appearance in Mozilla Firefox and Internet Explorer

When it comes to customizing the scrollbar in chrome, CSS makes it easy: ::-webkit-scrollbar { width: 7px; } Unfortunately, this method does not have the same result in Firefox (version 38) and IE (version 11). I attempted the following code as an alter ...

The impact of jQuery ajax on SVG data transmitted to a ColdFusion server appears to be significant

While using $.ajax() to send a string to a coldfusion server for storage in a table, I encountered an issue. Upon querying and attempting to use the data later on, an error message appeared stating "null Enclosed Exception: Invalid byte 2 of 3-byte UTF-8 s ...

Trouble With Ajax Submission in CakePhp: Issue with Form Serialization

In my attempt to utilize ajax for sending an array of objects along with serialized form data, I encountered a problem. The issue arises when I include the array in the ajax data along with the serialized form data. This results in the serialized form data ...

Issues verifying the selected value for the ajax request

One of the challenges I'm facing is related to a form that requires specific user selections. If the user chooses a value of 1, the form can be submitted without any additional steps. However, if they select values 2 or 3, they must then choose an opt ...

Can an additional height be added to the equalizer to increase its height?

Is it feasible to append an additional 35px to the height determined by Foundation Equalizer? For instance, if Equalizer computes a height of 350px, I would like to increase it by 35px. This means that the resultant style should be height: 385px; instead ...

Refresh the content of a webpage in AngularJS without the need to fully reload the entire page

Within my controller and view files, I have content that is sourced from various places, including API calls. For instance, I have information retrieved from the database where users can update certain details like their last name. After submitting the up ...

Guide to Using Jquery to Locate YouTube or Vimeo Videos Embedded in HTML

Is there a way to use Jquery, javascript or php to choose a YouTube or Vimeo video directly from a webpage? I would greatly appreciate any assistance! Many thanks ...