'Javascript quiz control flow
Can someone tell me what is wrong with the following 5 exercises? I got the other 95 Exercises right but these keep coming up as wrong on repl.
Can you tell me why these Exercises are wrong? What is the error in the 5 exercises?
I was told an error in 1 exercise can throw error in the rest.
// 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;
}
Solution 1:[1]
To get you started....
In the first exercise, you have an extra closing curly brace after the return. Additionally, you can only use return within a function, which your code is not inside of. Instead, you'd have to have the variable logged to the console or shown as an alert or displayed in some other way.
var aboutMe = {
name:'Brian',
city:'Columbus',
favoriteAnimal:'Dog'
};
console.log(aboutMe);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Scott Marcus |
