Uncaught ReferenceError: createRadio is not defined

Hey, I’m trying to use the createRadio() function, but I get this error:

Uncaught ReferenceError: createRadio is not defined
    at setup (p5js-temp-sketch_220402a1584838079584472986.js:4:3)
    at m.<anonymous> (p5.min.js:3:230028)
    at m.<anonymous> (p5.min.js:3:229048)
    at new m (p5.min.js:3:232427)
    at n (p5.min.js:3:226962)

my code:

let radio;

function setup() {
  radio = createRadio();
  radio.option('black');
  radio.option('white');
  radio.option('gray');
  radio.style('width', '60px');
  textAlign(CENTER);
  fill(255, 0, 0);
}

function draw() {
  let val = radio.value();
  background(val);
  text(val, width / 2, height / 2);
}

HTML file:

<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <!-- PLEASE NO CHANGES BELOW THIS LINE (UNTIL I SAY SO) -->
  <script language="javascript" type="text/javascript" src="libraries/p5.min.js"></script>
  <script language="javascript" type="text/javascript" src="p5js-temp-sketch_220402a1584838079584472986.js"></script>
  <!-- OK, YOU CAN MAKE CHANGES BELOW THIS LINE AGAIN -->

  <!-- This line removes any default padding and style.
       You might only need one of these values set. -->
  <style> body { padding: 0; margin: 0; } </style>
</head>

<body>
</body>
</html>

Do you have any idea?
Thanks :upside_down_face:

That’s strange. Your code runs perfectly on my browser, which is Chrome on a MacBook Air.

EDIT (April 2, 2022):

I did change the name of the sketch file, but that shouldn’t make a difference.

Yes that’s strange, if I use the P5 web editor it’s working, but if i use the Processing 4 IDE (in the p5.js mode) it raise that error

Perhaps you have a corrupt local copy of the p5.min.js file installed. If so, a fresh download of it could address the problem.

2 Likes

It worked!
thank you!

1 Like