Quick actions

cmd+k|ctrl+k

Navigation

Languages

Kuis Coding Custom Error

Snippet info

Language

JavaScript

Visibility

public

Author

ryandfbasketball12

Created

2022-11-11T02:20:12.921209Z

Updated

2022-12-01T04:19:56.298234Z

class ValidationError extends Error {
    constructor(message) {
        super(message);
        this.name = "ValidationError"
    }
}

const validateNumberInput = (a, b, c) => {
    if (typeof a != "number") {
        throw new ValidationError("Argumen pertama harus number");
    } else if(typeof b != "number") {
        throw new ValidationError("Argumen kedua harus number");
    } else if(typeof c != "number") {
        throw new ValidationError("Argumen ketiga harus number");
    }
}

const detectTriangle = (a, b, c) => {
  // TODO 3
  try {
      validateNumberInput(a, b, c)
  } catch (error) {
      return error.message
  }

  if (a === b && b === c) {
    return 'Segitiga sama sisi';
  }

  if (a === b || a === c || b === c) {
    return 'Segitiga sama kaki';
  }

  return 'Segitiga sembarang';
};
console.log(detectTriangle(1, 2, 12))
INFO