Javascript challenger

Complete the function named createImage(). This function takes in one
parameter (the source for the image file) and returns a new img element with
the scr reference to the parameter.

This is vanilla ES6,

const createImage = function (url) {
  return `<img src="${url}" alt="">`
}

Now one just needs to translate that to a JSX object.

Also, keep in mind that as long as you do convert this to return JSX instead, then you’ll be fine as far as injection attacks since JSX escapes any values embedded to help prevent XSS (cross-site scripting) attacks: https://reactjs.org/docs/introducing-jsx.html#jsx-prevents-injection-attacks

However, if you were going to use the function as it is right now, then you’d have to be very careful about what values you call it with.

1 Like