Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

219
Views
Uncaught ReferenceError: useStudent is not defined

I know this might be silly question and I might not asking this question the right way but I'm stuck on this part I keep trying to run this program and it says "Uncaught ReferenceError: useStudent is not defined" when I check the console on "Student" I check my script it's perfectly fine and my code

 
<script src="A2.js"></script>
<body>
  
  <div class="column1">
    <div class="input">
      
      <button onclick="useStudent()"> Student</button>
      <button onclick="useCar()"> Car</button>

      
    
</body>
</html>
here is my script added to this code
function useStudent(){
  var stu = "Jon Lee";
  
  var ye = 3;   
  console.log("year: " + ye);
  
  var maj = "Math"  
  console.log("major: " + maj)
  
  var message = stu.displayMe();
  console.log(message);
  
  console.log('-------------');
  
  // set year to be 4
  ye = 4;
  // set major to be "test"
  maj = "test";
  
  // output year and major
  console.log("year: " + ye);
  console.log("major: " + maj);
  
  message = stu.displayMe();
  console.log(message);
  
 }

here is displayme
displayMe() {
      this.id + this.name + this.Year + this.Major
  }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The "stu" type you defined is a string and it look like you need an object of student. therefore you need a conistractore function to create the student object and set the displayMe() method as its property.

function Stu (id,name, year,maj){
    this.id = id;
    this.name = name;
    this.year = year;
    this.major = maj;
    this.displayMe = function(){ return  this.id + this.name + this.year + this.major}
}

function useStudent(){
    let stu = new Stu(1,"Jon Lee",3,'Math')
    console.log("year: " + stu.year);
    console.log("major: " + stu.maj);
    console.log(stu.displayMe() );
    console.log('-------------');

    stu.maj = 'EECS';
    stu.year = 4;

    console.log("year: " + stu.year);
    console.log("major: " + stu.maj);
    console.log(stu.displayMe() );
    console.log('-------------');
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!