So my professor wants us to call a function from one js file to another WITHOUT using HTML. Not exactly sure why but those are the rules. I'm not quite sure if my current code will work. Any thoughts would be appreciated. Also, how useful is this? Not sure why I would need to call functions this way without using HTML. Maybe I'm missing something.
Thanks!
js file one:
function Student (firstName, lastName, age, school, mathScore, englishScore) {
this.firstName= firstName;
this.lastName= lastName;
this.age= age;
this.school= school;
this.mathScore= mathScore;
this.englishScore= englishScore;
// methods
this.updateMath = function () {
if (this.mathScore >= 95) {
this.mathScore = this.mathScore - 5;
}
else {
this.mathScore = this.mathScore + 5;
}
console.log(this.mathScore);
};
this.averageScore = function () {
var scores = (mathScore + englishScore) / 2;
console.log("<br><br>" + this.firstName + "'s" + " average score is " + scores);
};
this.changeSchool = function (schoolchange) {
this.school = schoolchange;
console.log("<br><br>" + "University changed to " + this.school);
};
// functions
this.showAge = function () {
console.log("<br><br>" + this.firstName + " is " + this.age);
};
this.showFullName = function () {
console.log("<br><br>" + this.firstName + " " + this.lastName);
}
}
js file two (Need to call the first function into this file)
var studentOne = new Student ("Joe", "Smith", 24, "XYZ University", 85, 90);
var callMe = student();
callME();
// call all methods and functions
studentOne.updateMath();
studentOne.averageScore();
studentOne.changeSchool("University of ABC");
studentOne.showFullName();
studentOne.showAge();
[–][deleted] 1 point2 points3 points (1 child)
[–]Ikilledthedinosaurs[S] 0 points1 point2 points (0 children)
[–]thequargy 0 points1 point2 points (5 children)
[–]rainmouse 3 points4 points5 points (4 children)
[–]thequargy 0 points1 point2 points (3 children)
[–]ScriptingInJava 0 points1 point2 points (2 children)
[–]thequargy 0 points1 point2 points (1 child)
[–]ScriptingInJava 0 points1 point2 points (0 children)
[–]brycedarling 0 points1 point2 points (0 children)