Question: "Modify the car-painting example so that the car is painted with your favorite color if you have one; otherwise it is painted w/ the color of your garage (if the color is known); otherwise it is painted red."
Car-painting example: 
car.color = favoriteColor || "black";

**How or what do I need to do to make my script work?**

```
car.color = favoriteColor || "red";
if (car.color = favoriteColor ){ 
    alert("your car is " + favoriteColor);

} else if (car.color = garageColor){
    alert("your car is " + garageColor);

} else {
    car.color = "red";
}

```

Answer: 
**This is the correct answer to your question:**

See my comments to get a better understanding of how this works.

```
if (favoriteColor) {
  car.color = favoriteColor; // If you have a favorite color, choose the favorite color.
} else if (garageColor) {
  car.color = garageColor;   // If the garage color is known, choose the garage color.
} else {
  car.color = 'red';         // Otherwise, choose the color 'red'.
}

alert('Your car is: ' + car.color);

```

**[Try it Online!](https://jsfiddle.net/jem6wp11/9/)**

**Related Question (for further insight):**

<https://softwareengineering.stackexchange.com/q/289475>

**Alternative Method:**

As another possibility, you can write a [conditional (ternary) operation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator) to compact all of the logic into a single statement.

```
alert('Your car is: ' + (car.color = favoriteColor ? favoriteColor : garageColor ? garageColor : 'red'));

```
Hope this code will be useful

```
function _showFavColor(getColor){
 var favoriteColor = 'red';
 var garageColor  ="blue";   
 var carColor = getColor;

if (carColor == favoriteColor ){ 
    alert("your car is " + favoriteColor);

} else if (carColor == garageColor){
    alert("your car is " + garageColor);

} else {
    carColor = "red";
}
}
_showFavColor('red');
_showFavColor('blue');

```

[jsfiddle](https://jsfiddle.net/c57da150/)

Also take a note on how eqality check is done in js. You can follow this links or google it
[Which equals operator (== vs ===) should be used in JavaScript comparisons?](https://stackoverflow.com/questions/359494/does-it-matter-which-equals-operator-vs-i-use-in-javascript-comparisons).

<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness>

Also if you use car.color and if dont create the car object it will throw an error 

```
 'Uncaught SyntaxError: Unexpected token . '

```