请这段代码有什么问题,这是我的作业,我不断出错

时间:2019-11-06 23:14:32

标签: javascript

上面的练习是由我的老师完成的,运行时我总是出错。

function exerciseOne() {
    // Exercise One: In this exercise you will create a variable called 'aboutMe'
    // This variable should be assigned a new object
    // In this object create three key:value pairs
    // The keys should be: 'name', 'city', 'favoriteAnimal'
    // The values should be strings associated with the keys.
    // return the variable 'aboutMe'

    let aboutMe = {
        name: 'Adebola Adesina',
        city: 'Los Angeles',
        favoriteAnimal: 'Zebra'
    };
    return aboutMe;
}

function exerciseTwo(animal) {
    // Exercise Two: In this exercise you will be given an object called 'animal'
    // Create a new variable called 'animalName'
    // Accessing the animal object, assign the 'animalName' variable to the 'latinName' key on the object.
    // return the animalName variable.

    animalName = animal.latinName;
}
return animalName;

function exerciseThree(userObject) {
    // Exercise Three: In this exercise you will be given an object called 'userObject'
    // The phonne number for this user is incorrect!
    // reassign the 'phoneNumber' key to the value: '(951)867-5309'
    // return the userObject

    userObject.phoneNumber = '(951)867-5309';
}
return userObject;

上面的练习是由我的老师完成的,运行时我总是出错。

1 个答案:

答案 0 :(得分:0)

function exerciseTwo(animal) {
    animalName = animal.latinName;
    return animalName;
}
function exerciseThree(userObject) {
    userObject.phoneNumber = '(951)867-5309';
    return userObject;
}

您必须返回函数内部的变量。了解javascript中的范围以及var和let之间的区别。另外,请仔细阅读错误并使用断点在浏览器中进行调试,您将了解代码在哪里中断。