Creating a custom CreditCardNumber type

Report a typo

Your task is to declare a custom type named CreditCardNumber based on the string type.

After declaring the custom type, you should also declare a variable named ccn of the CreditCardNumber type to capture a credit card number input from the user and then use the IsValid() method to check if it is a valid credit card number or not.

Sample Input 1:

4532015112830366

Sample Output 1:

This is a valid Credit Card Number!
Write a program in Go
package main

import "fmt"

// Declare a custom type `CreditCardNumber` derived from `string`:
type ? ?

func main() {
// Declare a variable `ccn` of the custom `CreditCardNumber` type:
var ? ?
fmt.Scanln(&ccn)

// Check if the credit card number `ccn` is valid using the `IsValid()` method:
if ccn.? {
fmt.Println("This is a valid Credit Card Number!")
} ? {
fmt.Println("This is not a valid Credit Card Number!")
}
}

// DO NOT delete or modify the `IsValid()` method below:
// nolint: gomnd // DO NOT remove this comment!
func (ccn CreditCardNumber) IsValid() bool {
var sum int
reverseOrder := false
for i := len(ccn) - 1; i >= 0; i-- {
n := int(ccn[i] - '0')
if reverseOrder {
n *= 2
if n > 9 {
n -= 9
}
}
sum += n
reverseOrder = !reverseOrder
}
___

Create a free account to access the full topic