Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

221
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda