React JS - prop

Hi,
Below is my code to play sound when user click the text link - using prop method, my text link is appearing in the browser but when I click the text link sound is not playing. I guess it might be the problem with the syntax in the 4th line of code — sound.src=“prop.sound”;
Can Some one help me please…

const TestSound = (prop) => { 

 const playSound=(prop) => {
        let sound = new Audio();
        sound.src = "prop.sound";
        sound.play();
    }

    return(
        
        <a href="#" onClick={playSound} > <h2>{prop.title}</h2></a>  
   
   )
  }

                      
export default TestSound;

onClick={this.playSound} or even onClick={ () => this.playSound}

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

Thanks for the info :+1:
I am very new here in free code camp forum.

Thanks for answering, but I cant solve with this solution.
Is line four is correct, I think prop might be used with some other syntax - not like “prop.sound” (as above)…Can you please figure out the mistake

I made it right :slightly_smiling_face:
it is -

sound.src = prop.sound;
1 Like