Search code examples
javascriptnodes

js code not running on node but it properly works on html


enter image description here

trying to run this code on node but comes up with this error

var weight = 350;
var time = 7;
var age = 77;
var gender = "male";
 if (weight > 300 && time < 6 && age > 17 && gender === "male") {
   alert("Come to our tryout!");
 }
 else {
   alert("Come to our cookout!");
 }

Solution

  • The function alert is implement by the browser window.

    Nodejs does not implement alert.

    You can use console.log() to output to the screen.

    Like this

    const weight = 350;
    const time = 7;
    const age = 77;
    const gender = "male";
     if (weight > 300 && time < 6 && age > 17 && gender === "male") {
       console.log("Come to our tryout!");
     }
     else {
       console.log ("Come to our cookout!");
     }