Greeting code

Report a typo

Here is a function description:

func Greeting(prefix string, name ...string) []string {...}

You need to write the code of a function that returns a slice of strings. Every string should have the following structure: prefix + whitespace + name.

For example:

Greeting("Hello,", "Rick", "Morty") // [Hello, Rick Hello, Morty]

In the input, you get three strings. The first string is a prefix, the other two are names. You need to output the result that the function returns line by line.

Sample Input 1:

Hello, Jerry Beth

Sample Output 1:

Hello, Jerry
Hello, Beth
Write a program in Go
package main

import "fmt"

func main() {
var prefix, name1, name2 string
fmt.Scan(&prefix, &name1, &name2)

for _, line := range Greeting(prefix, name1, name2) {
fmt.Println(line)
}
}

func Greeting(prefix ?, name ?) []string {
// your code goes here
}
___

Create a free account to access the full topic