Skip to content

Commit 411c820

Browse files
authored
fix(curriculum): add ternary example to music player step 70 (freeCodeCamp#55706)
1 parent d19cd8b commit 411c820

File tree

1 file changed

+6
-0
lines changed
  • curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-string-and-array-methods-by-building-a-music-player

1 file changed

+6
-0
lines changed

curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-string-and-array-methods-by-building-a-music-player/6555d729c9bfd7c3195f1948.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ const element = document.getElementById('example');
1818
console.log(element.textContent); // Output: This is some text content
1919
```
2020

21+
You can use a ternary operator to conditionally set the text content value. Here is an example of assigning the result of a ternary operator to a variable:
22+
23+
```js
24+
const example = condition ? "I'm true" : "I'm false";
25+
```
26+
2127
Use a ternary operator to check if `currentTitle` evaluates to a truthy value. If it does, set `playingSong.textContent` to `currentTitle`. Otherwise, set it to an empty string.
2228

2329
Then below that, use a `ternary` operator to check if `currentArtist` is truthy. If so, set `songArtist.textContent` to `currentArtist`. Otherwise, set it to empty string.

0 commit comments

Comments
 (0)