javascripthtmlreactjsbracketsdollar-sign

Why dollar sign and brackets inside string do not work? Javascript/npm/react


I am taking HTML/CSS/JS course. There is exercise to create web app with robofriends. There should be many robofriends photos, but I got return only the same. Could you please check if I am doing something wrong? Brackets inside string do not work: <img alt='robots' src={"https://robohash.org/${id}?200x200"} />

As is MyFriends

As should be RoboFriends

Code

    import React from 'react';



const Card = (props) => {
    const { email, name, id } = props;

    return (
        

        <div className="tc bg-light-green dib br3 pa3 ma2 grow bw2 shadow-5">
            <img alt='robots' src={"https://robohash.org/${id}?200x200"} />
            <div>
            <h2> {name} </h2>  
            <p>{email}</p>  
            </div>
        </div>
    );
}

export default Card;


    enter code here

Solution

  • Use backticks like so:

      <img alt='robots' src={`https://robohash.org/${id}?200x200`} />