diff --git a/curriculum/challenges/english/16-the-odin-project/top-learn-css-foundations-projects/css-foundations-exercise-e.md b/curriculum/challenges/english/16-the-odin-project/top-learn-css-foundations-projects/css-foundations-exercise-e.md index 0fef651b9a7..a721563d96d 100644 --- a/curriculum/challenges/english/16-the-odin-project/top-learn-css-foundations-projects/css-foundations-exercise-e.md +++ b/curriculum/challenges/english/16-the-odin-project/top-learn-css-foundations-projects/css-foundations-exercise-e.md @@ -7,38 +7,161 @@ dashedName: css-foundations-exercise-e # --description-- -description +Understanding how combinators work can become a lot easier when you start playing around with them and see what exactly is affected by them versus what isn't. + +The goal of this exercise is to apply styles to elements that are descendants of another element, while leaving elements that aren't descendants of that element unstyled. + +1. You should see a `yellow` background for `p` elements that are descendants of the `div` element. +1. You should see a text color of `red` for elements that are descendants of the `div` element. +1. You should see a font size of `20px` for elements that are descendants of the `div` element. +1. You should center align text for elements that are descendants of the `div` element. # --hints-- -Test 1 +You should have a background color of `yellow` on your descendants. ```js +const styleOne = new __helpers.CSSHelp(document).getStyle('.container .text'); +const styleTwo = new __helpers.CSSHelp(document).getStyle('div p'); +const styleThree = new __helpers.CSSHelp(document).getStyle('div .text'); +const styleFour = new __helpers.CSSHelp(document).getStyle('.container p'); + +const styles = [styleOne, styleTwo, styleThree, styleFour]; + +function getCorrectStyle(){ + for(let i = 0; i < styles.length; i++){ + if(styles[i] != undefined){ + return styles[i]; + } + } +} + +assert(getCorrectStyle()?.backgroundColor === 'yellow'); ``` -Test 2 +You should have a text color of `red` on your descendants. ```js +const styleOne = new __helpers.CSSHelp(document).getStyle('.container .text'); +const styleTwo = new __helpers.CSSHelp(document).getStyle('div p'); +const styleThree = new __helpers.CSSHelp(document).getStyle('div .text'); +const styleFour = new __helpers.CSSHelp(document).getStyle('.container p'); + +const styles = [styleOne, styleTwo, styleThree, styleFour]; + +function getCorrectStyle(){ + for(let i = 0; i < styles.length; i++){ + if(styles[i] != undefined){ + return styles[i]; + } + } +} + +assert(getCorrectStyle()?.color === 'red'); ``` -Test 3 +You should have a font size of `20px` on your descendants. ```js +const styleOne = new __helpers.CSSHelp(document).getStyle('.container .text'); +const styleTwo = new __helpers.CSSHelp(document).getStyle('div p'); +const styleThree = new __helpers.CSSHelp(document).getStyle('div .text'); +const styleFour = new __helpers.CSSHelp(document).getStyle('.container p'); + +const styles = [styleOne, styleTwo, styleThree, styleFour]; + +function getCorrectStyle(){ + for(let i = 0; i < styles.length; i++){ + if(styles[i] != undefined){ + return styles[i]; + } + } +} + +assert(getCorrectStyle()?.fontSize === '20px'); ``` +You should center align the text on your descendants. + +```js +const styleOne = new __helpers.CSSHelp(document).getStyle('.container .text'); +const styleTwo = new __helpers.CSSHelp(document).getStyle('div p'); +const styleThree = new __helpers.CSSHelp(document).getStyle('div .text'); +const styleFour = new __helpers.CSSHelp(document).getStyle('.container p'); + +const styles = [styleOne, styleTwo, styleThree, styleFour]; + +function getCorrectStyle(){ + for(let i = 0; i < styles.length; i++){ + if(styles[i] != undefined){ + return styles[i]; + } + } +} + +assert(getCorrectStyle()?.textAlign === 'center'); + +``` # --seed-- ## --seed-contents-- -```html +```css +``` +```html + + +
+This should be styled.
+This should be unstyled.
+This should be unstyled.
+This should be styled.
+This should be styled.
+This should be styled.
+This should be unstyled.
+This should be unstyled.
+This should be styled.
+This should be styled.
+