if else statement not working(nodejs,html)

I have this code that will get the year from a html form and im trying to set an argument for it but the else statement never seem to execute. Any clue as to why?

exports.printyear = function(request, response) {
        let form = new formi.IncomingForm();
        form.parse(request, function(error, field, file) {
            let year = field.year;
            let currenturl = "";
            console.log("YEAR");
            console.log(year);
            if (year === 2007 | 2008 | 2009) {
                currenturl = "websiteurl" + year + ".xml";
            } else {
                currenturl = "websiteurl" + year + ".json";
            }
            console.log(currenturl);
            response.end();
        });

>Solution :

The right way of using or in conditions is to separate them.

Change

if (year===2007|2008|2009) {

To

if (year===2007 || year===2008 || year===2009) {

Leave a Reply