Having difficulty accessing the sound file despite inputting the correct path. Attempts to open it using ./ , ../ , and ../../ were unsuccessful

While attempting to create a blackjack game, I encountered an issue. When I click the hit button, a king card picture should appear along with a sound. However, the sound does not play and the error message Failed to load resource: net::ERR_FILE_NOT_FOUND is displayed. Here is a link to the image that should be loaded: https://i.stack.imgur.com/P5ZoQ.jpg

Here are the paths to the project folder: https://i.stack.imgur.com/CWXuA.png

I have tried changing the source path formats like /statics, ../../statics, but unfortunately, it did not resolve the issue.

Below is the relevant part of my code for better understanding:

HTML section

    <div class="playerContainer">
        <div class="playerChoice">
            <h1 id="playerScore"> You: <span id="playerResult"> 0 </span> </h1>
        </div>
        <div class="botChoice">
            <h1 class="dealerResult"> Computer: <span id="dealerResult"> 0 </span> </h1>
        </div>
    </div>
    <div class="controls">
        <button id="standBtn"class="btn-lg btn-warning mr-2">stand</button>
        <button id="dealBtn"class="btn-lg btn-danger mr-2">deal</button>
        <button id="hitBtn"class="btn-lg btn-primary mr-2">hit</button>
    </div>

JS section

let blackJackGame = {
    'you' : {'scoreSpan':'#playerResult','div': '.playerChoice', 'score': 0},
    'bot' : {'scoreSpan':'#dealerResult','div': '.botChoice', 'score': 0}
};

const YOU = blackJackGame['you'];
const BOT = blackJackGame['bot'];
const hitSound = new Audio('../statics/sounds/Ta Da-SoundBible.com-1884170640');

document.querySelector('#hitBtn').addEventListener('click',blackJackHit);

function blackJackHit() {
    let cardImage = document.createElement('img');
    cardImage.src = 'B:/Html, CSS & Js/js excersing/photos/KS.png'
    document.querySelector(YOU['div']).appendChild(cardImage);
    hitSound.play();
}

The error appears in this line of JS code:

const hitSound = new Audio('../statics/sounds/Ta Da-SoundBible.com-1884170640');

Answer â„–1

  1. Make sure to include the audio file extension in your file path for it to work properly.
  2. The correct path format should be something like ../sounds/file.extension.

If you're using VSCode, I suggest installing the Path Intellisense extension to streamline similar tasks in the future.

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

The Jquery function is failing to retrieve data from the MySQL database

I am currently attempting to retrieve values from phpMyAdmin and populate them into the second select field based on the selection made in the first select field. However, I seem to be encountering an issue as the selected value is not being passed to my P ...

function instance is causing confusion with the hasOwnProperty() method

When looking at the code example provided, it is interesting to note that the doOtherStuff function is defined directly on the b instance, rather than being higher up in the prototype chain (like on base or Object). This leads to a situation where b.hasOwn ...

Retrieving ng-model using ng-change in AngularJS

Here is an example of the HTML code I am currently working with: <select ng-model="country" ng-options="c.name for c in countries" ng-change="filterByCountry"></select> This HTML snippet is being populated by the following object containing a ...

Effects with Cleanup - terminates ongoing API calls during cleanup process

Developing a React album viewing application: The goal is to create a React app that allows users to view albums. The interface should display a list of users on the left side and, upon selecting a user, show a list of albums owned by that user on the righ ...

How to Pause or Temporarily Halt in Jquery?

Looking to lift the object up, wait 1000ms, and then hide it. I found this snippet of code: $("#test").animate({"top":"-=80px"},1500) .animate({"top":"-=0px"},1000) .animate({"opacity":"0"},500); However, using ".animate({"to ...

An effective method for retrieving the version from package.json

I am currently in the process of developing an SDK that will soon be available on npm. One of the requirements for this SDK is to deliver its version to the client. My goal is to have this version match the one specified in the package.json file. However ...

Using inertia-links within the storybook framework

Hey there, just wanted to share my experience with storybook - I'm really enjoying it so far! Currently, I'm facing a challenge while implementing it in my Laravel app with Inertia. I'm trying to render a navigation link component that make ...

Reveal the administrator's details exclusively when the associated radio button is chosen

Managing administrators for a post can be done through an editing page with corresponding radio buttons. Each radio button is linked to a different administrator, and selecting one populates the form fields with that admin's details. The issue arises ...

Customize Column Headers in Handsontable: A Quick Guide

Is there a way to customize the appearance of column headers in handsontable? I have provided a jsfiddle example to showcase my current progress. While I am able to format the first row of data and change the column titles, I am facing difficulty in forma ...

Using scope in ng-style to manipulate a portion of a CSS property value in Angular

I've been attempting to add a border using ng-style, but I'm struggling to figure out how to concatenate the value from the scope variable. None of the methods below seem to be working for me: <div ng-style="{'border-top' :'1p ...

Customize RequireJS dependencies for flexible dependency injection

Currently, I am faced with integrating a component that would greatly benefit from Dependency Injection (DI) into an existing framework where DI was not considered during its initial design. The configuration defining dependencies is sourced from a backend ...

Simulating a traditional table scroll function on a window using virtualization

I am currently attempting to incorporate a virtualized table in react using react–virtualized, but I am facing issues with the rendering of the table. I am seeking to understand the root cause for this problem as well as find solutions for other overlapp ...

AngularJS flexible route parameter

My AngularJS application has routes that can be either: www.website.com/blog/xyz www.website.com/blog/xyz/title/other-params In the second URL, the title parameter is used for readability purposes only and is not mandatory in the URL. Therefore, I have i ...

The jQuery .hasClass() function does not work properly with SVG elements

I am working with a group of SVG elements that are assigned the classes node and link. My goal is to determine whether an element contains either the node or link class when hovering over any of the SVG components. However, I am encountering an issue where ...

My code written using Visual Studio Code is not displaying properly when I view it in my browser

I have been following along with a tutorial series that can be found at this link. This link will take you to the third video in the series, but I have also followed and programmed alongside the first and second videos. After installing Visual Studio Code ...

What are the best ways to make this date more visually appealing and easy to understand?

Hey there! So I have a date that looks like this: 2022-06-28T17:09:00.922108+01:00 I'm trying to make it more readable, but unfortunately, when I attempted using moment-js in my javascript/react project, it threw an error stating "invalid format". ...

Do you think my approach is foolproof against XSS attacks?

My website has a chat feature and I am wondering if it is protected against XSS attacks. Here is how my method works: To display incoming messages from an AJAX request, I utilize the following jQuery code: $("#message").prepend(req.msg); Although I am a ...

Tips on navigating an array to conceal specific items

In my HTML form, there is a functionality where users can click on a plus sign to reveal a list of items, and clicking on a minus sign will hide those items. The code structure is as follows: <div repeat.for="categoryGrouping of categoryDepartm ...

Sending JavaScript objects from React.js to Node.js

I send the object to the backend (Node js) when making an API call, but I am logging the objects for verification. Initially, I used POSTMAN to check and it worked perfectly. However, when attempting to pass an object in the frontend (Reactjs), it appear ...

Using AJAX to dynamically update content via HTTP requests

Why do I keep seeing "loading..." instead of the content from data.php? xmlhttp = new XMLHttpRequest(); function fetchData () { xmlhttp.onreadystatechange = function () { if(xmlhttp.readyState = 4 && xmlhttp.status == 20 ...