Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

366
Views
How the empty line gives an error in JavaScript (Uncaught SyntaxError: Unexpected end of input)

I have this error in javascript code : (JavaScript error (Uncaught SyntaxError: Unexpected end of input)) I saw many questions same as this, but could not solve my error, so now ask help My code is so simple as follows;

const playBtn = document.querySelector('.play')
const audio = new Audio('/sounds/1M.mp4')

function playAudio(){
    for (i = 0; i < 5; i++){
        audio.play();
        audio.loop = true;
        audio.playbackRate = 2;
}

playBtn.addEventListener('click', ()=> {
    playAudio()
})

Why this kind of error comes out from my code? Uncaught SyntaxError: Unexpected end of input) : audio.js 14 (line 14 is the empty line next the end of parenthesis '})' How the empty line gives an error ?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You didn't close the for loop

const playBtn = document.querySelector('.play')
const audio = new Audio('/sounds/1M.mp4')

    function playAudio(){
        for (i = 0; i < 5; i++){
            audio.play();
            audio.loop = true;
            audio.playbackRate = 2;
        }
    }
    playBtn.addEventListener('click', ()=> {
        playAudio()
    })
about 4 years ago · Juan Pablo Isaza Report

0

It is because you forgot to close the playAudio function when defining it. You can fix it like this:

const playBtn = document.querySelector('.play')
const audio = new Audio('/sounds/1M.mp4')

function playAudio() {
  for (i = 0; i < 5; i++) {
    audio.play();
    audio.loop = true;
    audio.playbackRate = 2;
  } // <---
}

playBtn.addEventListener('click', () => {
    playAudio();
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!