settingsAccountsettings
Menusettings

Q: Compose an HTML image tag in JavaScript

+2 votes

Write a JS function that composes an HTML image tag.

The input comes as an array of string elements. The first element is the location of the file and the second is the alternate text.

Examples:

Input:
['smiley.gif', 'Smiley Face']

Output:
<img src="smiley.gif" alt="Smiley Face">


The output should be printed to the console in the following format:
<img src="{file location}" alt="{alternate text}">

asked in JavaScript category by user paulcabalit

1 Answer

+1 vote

My js solution to this interesting javascript task:

function composeTag(input) {
    let img = input[0];
    let alt = input[1];

    console.log("<img src=" + "\"" + img + "\" " + "alt=" + "\"" + alt + "\"" + ">");
//Second option for console.log(); with single '' quotes:
//    console.log('<img src=' + '"' + img + '" ' + 'alt=' + '"' + alt + '"' + '>');
}

composeTag(['smiley.gif', 'Smiley Face']);

 

answered by user sam
...