Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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) {
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading