JSFiddle - React, Tailwind, and code Playground

by hslincoln

JavaScript

function Value(obj) {
    var output;
    // Check if there is obj passed as parameter
    if (obj) {
        // Check if obj.value, min and max are type of number, if not then error.
        if(typeof obj.value === 'number' && typeof obj.min === 'number' && typeof obj.max === 'number') {
            var max = obj.max;
            var min = obj.min;
            var value = obj.value;
            
            //Check if value is Out of bounds
            if ((value < min) || (value > max)) {
                    output = 'Error: Out of bounds';
            } else {
                    output = value;
            }
        } else {
            output = 'Error: Out of bounds';
        }        
    } else {
        output = 0;
    }
    return output;
}
alert(Value({
    value: 101,
    min: 0,
    max: 100
}));
alert(Value());