/* globals $ */

/* 

 Create a function that takes a selector and COUNT, then generates inside a UL with COUNT LIs:
 * The UL must have a class `items-list`
 * Each of the LIs must:
 * have a class `list-item`
 * content "List item #INDEX"
 * The indices are zero-based
 * If the provided selector does not selects anything, do nothing
 * Throws if
 * COUNT is a `Number`, but is less than 1
 * COUNT is **missing**, or **not convertible** to `Number`
 * _Example:_
 * Valid COUNT values:
 * 1, 2, 3, '1', '4', '1123'
 * Invalid COUNT values:
 * '123px' 'John', {}, []
 */
function isNumber(number) {
    if (number === '' || number === ' ' || number === []) {
        return false;
    }
    else return Number(number) == number;
}
function solve() {
    return function (selector, count) {
        if (typeof selector!=='string') {
            throw Error();
        }
        var $domElement = $(selector);

        if ($domElement === null) {
            return;
        }
        if (count === undefined || !isNumber(count)) {
            throw new Error();
        }
        if(Number(count)<1)
        {
            throw Error();

        }
        var $list = $('<ul>');
        $list.addClass("items-list");
        for (var i = 0; i < Number(count); i += 1) {
            $list.append('<li class="list-item">List item #' + i + '</li>');

        }
        $domElement.append($list);


    }
        ;
};

module.exports = solve;