Single Function: Product Return

const factorial = function fac(n) {         // calls a function which performs a calculation and returns the result
  return n < 2 ? 1 : n * fac(n - 1);
}

console.log(factorial(7))
5040

Set of Functions and Definitions: JSON Lists and Prototypes

function printInfo(msg) {           // Necessary definition 
    console.log(typeof msg + ";", msg);
}

function Media(name, cre, date) {       // Define media
    this.name = name;
    this.cre = cre;
    this.date = date;
    this.type = "";
}

Media.prototype.setType = function(type) {          // Introduce prototype
    this.type = type;
}

Media.prototype.toJSON = function() {           // organize
    const data = {name: this.name, cre: this.cre, date: this.date, type: this.type};
    const jsonString = JSON.stringify(data);
    return jsonString;
}

var album = new Media("Kid A", "Radiohead", 2000);              // song variable
album.setType("Album");

var movie = [               // movie variables
    new Media("Whiplash", "Damien Chazelle", 2014),
    new Media("Atonement", "Joe Wright", 2007),
    new Media("Prestige", "Christopher Nolan", 2006)
]

var show = [            // show variables
    new Media("Fargo", "Noah Hawley", 2014),
    new Media("Daredevil", "Kati Johnson", 2015),
]

function Medias(album, movie, show) {
    album.setType("Album");
    this.album = album;
    this.medias = [album];
    this.movie = movie;
    this.show = show;
    this.movie.forEach(movie => {movie.setType("Movie"); this.medias.push(movie);});
    this.show.forEach(show => {show.setType("Show"); this.medias.push(show);});
    this.jsonMedias = [];
    this.medias.forEach(media => this.jsonMedias.push(media.toJSON()));
}

catalog = new Medias(album, movie, show);

printInfo(catalog.medias);
printInfo(catalog.medias[4].name);
printInfo(catalog.jsonMedias[4]);
printInfo(JSON.parse(catalog.jsonMedias[4]));
object; [ Media { name: 'Kid A', cre: 'Radiohead', date: 2000, type: 'Album' },
  Media {
    name: 'Whiplash',
    cre: 'Damien Chazelle',
    date: 2014,
    type: 'Movie' },
  Media {
    name: 'Atonement',
    cre: 'Joe Wright',
    date: 2007,
    type: 'Movie' },
  Media {
    name: 'Prestige',
    cre: 'Christopher Nolan',
    date: 2006,
    type: 'Movie' },
  Media { name: 'Fargo', cre: 'Noah Hawley', date: 2014, type: 'Show' },
  Media {
    name: 'Daredevil',
    cre: 'Kati Johnson',
    date: 2015,
    type: 'Show' } ]
string; Fargo
string; {"name":"Fargo","cre":"Noah Hawley","date":2014,"type":"Show"}
object; { name: 'Fargo', cre: 'Noah Hawley', date: 2014, type: 'Show' }