# How come that function getLevel() doesn't work: Uncaught TypeError: Cannot read properties of undefined (reading 'getLevel')

**URL:** <https://discourse.processing.org/t/how-come-that-function-getlevel-doesnt-work-uncaught-typeerror-cannot-read-properties-of-undefined-reading-getlevel/34588>\
**Category:** Libraries\
**Created:** [January 11, 2022, 8:50pm UTC](https://discourse.processing.org/t/how-come-that-function-getlevel-doesnt-work-uncaught-typeerror-cannot-read-properties-of-undefined-reading-getlevel/34588 "2022-01-11T20:50:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joeri](https://avatars.discourse-cdn.com/v4/letter/j/977dab/32.png) [@Joeri](https://discourse.processing.org/u/Joeri)\
**Post date:** [January 11, 2022, 8:50pm UTC](https://discourse.processing.org/t/how-come-that-function-getlevel-doesnt-work-uncaught-typeerror-cannot-read-properties-of-undefined-reading-getlevel/34588/1 "2022-01-11T20:50:58Z")

</div>

I started a project in VS code and at the beginning everything was working but now I get the TypeError. How come? Thanks

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [January 11, 2022, 9:02pm UTC](https://discourse.processing.org/t/how-come-that-function-getlevel-doesnt-work-uncaught-typeerror-cannot-read-properties-of-undefined-reading-getlevel/34588/2 "2022-01-11T21:02:06Z")

</div>

hi and welcome

can you post your sketch

---

<div class="post-metadata">

**Author:** ![Joeri](https://avatars.discourse-cdn.com/v4/letter/j/977dab/32.png) [@Joeri](https://discourse.processing.org/u/Joeri)\
**Post date:** [January 11, 2022, 9:20pm UTC](https://discourse.processing.org/t/how-come-that-function-getlevel-doesnt-work-uncaught-typeerror-cannot-read-properties-of-undefined-reading-getlevel/34588/3 "2022-01-11T21:20:54Z")

</div>

Hello, here is my code: The problem is in function draw. “let level = amp.getLevel();”. He doesn’t understand the function getLevel() from p5.js. When I’m using the same code in the editor of p5 there is no problem, in Visual Studio Code (live server) there is a problem =\> TypeError. Thanks

let sound;  
let amp;

function preload() {

soundFormats(‘mp3’, ‘ogg’);

sound = loadSound(‘song3.mp3’);

}

function setup() {

let cnv = createCanvas(600,600);

cnv.mouseClicked(togglePlay);

amplitude = new p5.Amplitude();

}

function draw() {

background(‘red’);

let level = amp.getLevel();

let size = map(level, 0, 1, 0, width/1.9);

console.log(size);

if(size\<50) {

```
fill('white');

```

}else if(size\<75) {

```
fill('green');

background('red');

```

}else if(size\<100) {

```
fill('yellow');

background('blue');

```

} else {

```
fill('blue');

background('yellow');

```

}

circle(width/2, height/2, size);

}

function togglePlay() {

if (sound.isPlaying() ){

```
sound.pause();

```

} else {

```
sound.loop();

amplitude = new p5.Amplitude();

amplitude.setInput(sound);

```

}

}

document.getElementById(“knop”).addEventListener(“click”, pauzeSound);

function pauzeSound() {

console.log(“knoop werkt naar behoren”);

let thissound = sound;

thissound.pause();

thissound.currentTime = 0;

}

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [January 11, 2022, 11:45pm UTC](https://discourse.processing.org/t/how-come-that-function-getlevel-doesnt-work-uncaught-typeerror-cannot-read-properties-of-undefined-reading-getlevel/34588/4 "2022-01-11T23:45:31Z")

</div>

> **[reference | p5.js](https://p5js.org/reference/#/p5.Amplitude/getLevel)**
>
> p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.

> **[p5.js Web Editor](https://editor.p5js.org/weidi/sketches/0kbXoXKtO)**
>
> A web editor for p5.js, a JavaScript library with the goal of making coding accessible to artists, designers, educators, and beginners.

[https://creative-coding.decontextualize.com/synthesizing-analyzing-sound/](https://creative-coding.decontextualize.com/synthesizing-analyzing-sound/)
