Поток управления викториной Javascript - PullRequest
1 голос
/ 27 октября 2019

Может кто-нибудь сказать мне, что не так со следующими 5 упражнениями? Я правильно выполнил остальные 95 упражнений, но они все равно выглядят неправильно.

Можете ли вы сказать мне, почему эти упражнения неправильны? В чем ошибка в 5 упражнениях?

Мне сказали, что ошибка в 1 упражнении может привести к ошибке в остальных.

// 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'

var aboutMe = {
  name: 'Brian',
  city: 'Columbus',
  favoriteAnimal: 'Dog'
};

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.
}

let animalName = {
  animalName: 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;
}

function exerciseFour(value) {
  let greaterThanFive = true;
  // In this exercise, you will be given a variable, it will be called: value
  // You will also be given a variable named: greaterThanFive
  // Using an 'if' statement check to see if the value is greater than 5. If it is, re-assign greaterThanFive the boolean true.
  if (value > 5) {
    value = greaterThanFive
  }

  // Please write your answer in the line above.
  return greaterThanFive;
}

function exerciseFive(name) {
  let isSondra = false;
  // In this exercise, you will be given a variable, it will be called: name
  // You will also be given a variable named: isSondra
  // Using an 'if' statement check to see if the name is equal to the string 'Sondra'. If it is, re-assign isSondra the boolean true.
  if (name = isSondra) {
    return true
  } else {
    false
  }
  // Please write your answer in the line above.
  return isSondra;
}

1 Ответ

0 голосов
/ 27 октября 2019

Для начала ....

В первом упражнении у вас есть дополнительная закрывающая фигурная скобка после return. Кроме того, вы можете использовать return только внутри функции, внутри которой нет вашего кода. Вместо этого вам нужно будет зарегистрировать переменную на консоли, либо отобразить ее как alert, либо как-то иначе.

var aboutMe = {
  name:'Brian',
  city:'Columbus',
  favoriteAnimal:'Dog'
};

console.log(aboutMe);
...