0

5 つのプロパティを求めるプロンプトを表示し、テスト スコアを取得してテスト 1、2、および 3 の平均を取得し、名前と平均を表示する必要があります。関数を表示または実行することはできません。コードの何が問題になっていますか?

function Student(_firstName, _lastName, _t1, _t2, _t2){

    this.firstName = _firstName ;
    this.lastName = _lastName ;
    this.test1 = _t1 ;
    this.test2 = _t2 ;
    this.test3 = _t3 ;

    this.fullName = function() { return this.firstName + " " + this.lastName } ;

    this.calcAverage = function() { return (this.test1 + this.test2 + this.test3) / 3 } ;

}

var name1 = prompt("Enter the first name:") ;
var name2 = prompt("Enter the last name:") ;
var te1 = parseInt(prompt("Enter the first test score:")) ;
var te2 = parseInt(prompt("Enter the second test score:")) ;
var te3 = parseInt(prompt("Enter the third test score:")) ;

var person = new Student(name1, name2, te1, te2, te3) ;

document.write(+name1+ " " +name2+ " " + person.calcAverage() +) ;
4

2 に答える 2

0

タイプミスを修正してください:

function Student(_firstName, _lastName, _t1, _t2, _t3) {
                                                   ^^ _t3, not _t2

document.write(+ name1 + " " + name2 + " " + person.calcAverage() +);
               ^^ remove +                                        ^^ remove +

デモ

于 2015-05-08T14:56:50.547 に答える
0

作業コード...

function Student(_firstName, _lastName, _t1, _t2, _t3) {

    this.firstName = _firstName;
    this.lastName = _lastName;
    this.test1 = _t1;
    this.test2 = _t2;
    this.test3 = _t3;

    this.fullName = function () {
        return this.firstName + " " + this.lastName
    };

    this.calcAverage = function () {
        return (this.test1 + this.test2 + this.test3) / 3;
    };

}

var name1 = prompt("Enter the first name:");
var name2 = prompt("Enter the last name:");
var te1 = parseInt(prompt("Enter the first test score:"));
var te2 = parseInt(prompt("Enter the second test score:"));
var te3 = parseInt(prompt("Enter the third test score:"));

var person = new Student(name1, name2, te1, te2, te3);

document.write(+name1 + " " + name2 + " " + person.calcAverage());
于 2015-05-08T14:55:53.680 に答える