Testing Code in Browser and Visual Code Console

Hi ,

I am trying to test some code in the Browser console and Visual Studio Code console, but it is not functioning as of yet. I have put the following in:

var eatSound;

function preload() {
	eatSound = loadSound("clong-2.wav");
	
}

The sound file is in the same folder , can anybody shed any light on this matter?

Thanks in advance.

Hello there,

What do you expect the code to do?

Hi,

Just to play the mp3 sound file when it loads in the browser.

Thanks.

  • Are you using any library with this?
  • Is this linked to any HTML file?
  • What is calling preload?
  • Where is loadSound defined?

Ideally, it would be easiest if you could link to a CodePen/Replit/Glitch/CodeSandbox, or GitHub repo?

1 Like

Hi,
Thanks for the reply. I came across the code from a You Tube video here:
17.5: Adding Sound Effects - p5.js Sound Tutorial - YouTube

So I will probably will need to use a library, but I am familiar with how to use them as of yet.

Right. Thank you, for sharing the context.

If the original post’s code is all the code you have, then nothing should happen. If you are unfamiliar with getting the setup for p5js, then I suggest you use their in-browser editor environment: https://editor.p5js.org/

Otherwise, I highly recommend the earlier videos by The Coding Train (Dan Shiffman), where he explains the fundamentals of using p5js locally.

The typical workflow is (and you can find this in the p5js docs):

  1. Create an HTML file that uses a script tag to link to the p5js CDN
  2. Add another script tag linking your local JavaScript file
  3. Then, the p5js library (i.e. functions) are available for use within the linked local JS file

Hope this helps

Not sure, if this will be helpful enough, as everybody’s situation is different, but I have set up VS Code and Node JS. This way, I work on *.js files in Code, and cd into the dir with that file, and run it with Node using node filename.js
It’s a little bit different than the editor here (e.g., return normally shows nothing when *.js files are run, so I debug while coding by using console.log("debug text here")
I’m also finding Node to be extremely useful, even on its own (e.g., I type anything I want to check, and it shows the result immediately). The same can be done with a browser console, though.
I easily switch between Code and Node by Ctrl + ` (Control + backtick char). I haven’t tried to play sound or video files with it yet, though :slight_smile: :sunglasses:

Hi,

Thanks to both of you for your replies. I will look into this as it seems interesting.

Regards.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.