In lines 04 and 08, which code allows the user to select an image from their local computer, and to display the image in the browser?

is below:

<input type=”file” onchange=”previewFile()”> <img src=”” height=”200” alt=”Image Preview…”/> The JavaScript portion is:

01 function previewFile(){

02 const preview = document.querySelector(‘img’);

03 const file = document.querySelector(‘input[type=file]’).files[0];

04 //line 4 code

05 reader.addEventListener(“load”, () => {

06 preview.src = reader.result;

07 },false);

08 //line 8 code

09 }

In lines 04 and 08, which code allows the user to select an image from their local computer, and to display the image in the browser?
A . 04 const reader = new File();
08 if (file) UR
B . createObjectURL(file);
C . 04 const reader = new FileReader();
08 if (file) UR
D . createObjectURL(file);
E . 04 const reader = new File();
08 if (file) reader.readAsDataURL(file);
F . 04 const reader = new FileReader();
08 if (file) reader.readAsDataURL(file);

Answer: D

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments