0

This is my code and everytime when I try to access the (car1.topSpeed) in browser console it shows me an error(car1 is not defined) what to do ?

//Creating a constructer for cars
function GeneralCar(givenName,givenSpeed){
    this.name = givenName;
    this.topSpeed = givenSpeed;
    this.run = function(){
        console.log(`${this.name} is running`);
    }
    this.analyze = function(){
        console.log('This car is slower by ${200 - this.topSpeed} than Mercedes')
    }
}
let car1 = new GeneralCar('Tesla',120);          //Here creating a new car with the help of the constructer(GeneralCar).
let car2 = new GeneralCar('Maruti',80);
console.log(car1,car2);
Barmar
  • 741,623
  • 53
  • 500
  • 612
Deb
  • 1
  • 1
  • 1
    This issue is not reproducible. But please see [ECMAScript template literals like 'some ${string}' are not working](/q/37245679/4642212). – Sebastian Simon Feb 08 '22 at 18:26
  • Please paste the exact error message. – Barmar Feb 08 '22 at 18:26
  • 1
    Is the code you posted inside a function? Then the scope of the variable will be the function, and you won't be able to access it from the top-level console. Set a breakpoint in the function. – Barmar Feb 08 '22 at 18:27
  • The context where your code is run is needed in order to understand the issue. – jamomani Feb 18 '22 at 13:39

0 Answers0