makeTags Solution

For the makeTags problem we’re given an HTML tag and a piece of text and need to wrap the text in the tag. So if the tag is "i" and the text is "Yay" we need to return the string "<i>Yay</i>".

Examples

makeTags("i", "Yay") => "<i>Yay</i>"
makeTags("i", "Hello") => "<i>Hello</i>"
makeTags("cite", "Yay") => "<cite>Yay</cite>"

Starter Code

public String makeTags(String tag, String word) {

}

Solution

public String makeTags(String tag, String word) {
    return "<" + tag + ">" + word + "</" + tag + ">";
}

What most students find confusing on this problem is that we’re just concatenating so many things. We normally do this question as a warm-up early in the year and have done labs with concatenation. But most of them are concatenating 2 or 3 things. This question you’re concatenating 7 things, and it’s a mix of parameter values and string literals.

The other common sticking point is that the parameter tag is used twice. Of course it makes perfect sense once you see the solution, but this is often the first time that students have used the same parameter or variable twice in the same command.

This site contains affiliate links. If you click an affiliate link and make a purchase we may get a small commission. It doesn't affect the price you pay, but it is something we must disclose.