--- id: 5a24c314108439a4d4036188 title: Render Conditionally from Props challengeType: 6 isRequired: false videoUrl: '' localeTitle: تجعل مشروط من الدعائم --- ## Description undefined ## Instructions undefined ## Tests
```yml tests: - text: يجب أن يتواجد مكون GameOfChance وأن يتم GameOfChance إلى الصفحة. testString: 'assert.strictEqual(Enzyme.mount(React.createElement(GameOfChance)).find("GameOfChance").length, 1, "The GameOfChance component should exist and render to the page.");' - text: يجب أن تقوم GameOfChance بإرجاع عنصر button واحد. testString: 'assert.strictEqual(Enzyme.mount(React.createElement(GameOfChance)).find("button").length, 1, "GameOfChance should return a single button element.");' - text: يجب أن تقوم GameOfChance بإرجاع نسخة واحدة من مكون Results ، الذي يحتوي على سند باسم fiftyFifty . testString: 'assert(Enzyme.mount(React.createElement(GameOfChance)).find("Results").length === 1 && Enzyme.mount(React.createElement(GameOfChance)).find("Results").props().hasOwnProperty("fiftyFifty") === true, "GameOfChance should return a single instance of the Results component, which has a prop called fiftyFifty.");' - text: يجب تهيئة حالة GameOfChance مع خاصية counter لتعيين قيمة 1 . testString: 'assert.strictEqual(Enzyme.mount(React.createElement(GameOfChance)).state().counter, 1, "GameOfChance state should be initialized with a property of counter set to a value of 1.");' - text: 'عندما يتم تقديم مكون GameOfChance أولاً إلى DOM ، يجب إرجاع عنصر p مع النص الداخلي لـ Turn: 1 .' testString: 'assert.strictEqual(Enzyme.mount(React.createElement(GameOfChance)).find("p").text(), "Turn: 1", "When the GameOfChance component is first rendered to the DOM, a p element should be returned with the inner text of Turn: 1.");' - text: 'في كل مرة يتم النقر فوق الزر ، يجب زيادة حالة العداد بقيمة 1 ، ويجب تقديم عنصر p واحد إلى DOM الذي يحتوي على النص "Turn: N" ، حيث N هي قيمة حالة العداد.' testString: 'async () => { const waitForIt = (fn) => new Promise((resolve, reject) => setTimeout(() => resolve(fn()), 250)); const comp = Enzyme.mount(React.createElement(GameOfChance)); const simulate = () => { comp.find("button").simulate("click"); };const result = () => ({ count: comp.state("counter"), text: comp.find("p").text() });const _1 = () => { simulate(); return waitForIt(() => result())}; const _2 = () => { simulate(); return waitForIt(() => result())}; const _3 = () => { simulate(); return waitForIt(() => result())}; const _4 = () => { simulate(); return waitForIt(() => result())}; const _5 = () => { simulate(); return waitForIt(() => result())}; const _1_val = await _1(); const _2_val = await _2(); const _3_val = await _3(); const _4_val = await _4(); const _5_val = await _5(); assert(_1_val.count === 2 && _1_val.text === "Turn: 2" && _2_val.count === 3 && _2_val.text === "Turn: 3" && _3_val.count === 4 && _3_val.text === "Turn: 4" && _4_val.count === 5 && _4_val.text === "Turn: 5" && _5_val.count === 6 && _5_val.text === "Turn: 6", "Each time the button is clicked, the counter state should be incremented by a value of 1, and a single p element should be rendered to the DOM that contains the text "Turn: N", where N is the value of the counter state."); }; ' - text: عندما يتم أولاً تثبيت المكون GameOfChance إلى DOM و في كل مرة يتم النقر فوق الزر بعد ذلك ، يجب إرجاع عنصر h1 مفرد يعرض عشوائياً إما You Win! أو You Lose! . testString: 'async () => { const waitForIt = (fn) => new Promise((resolve, reject) => setTimeout(() => resolve(fn()), 250)); const comp = Enzyme.mount(React.createElement(GameOfChance)); const simulate = () => { comp.find("button").simulate("click"); };const result = () => ({ h1: comp.find("h1").length, text: comp.find("h1").text() });const _1 = result(); const _2 = () => { simulate(); return waitForIt(() => result())}; const _3 = () => { simulate(); return waitForIt(() => result())}; const _4 = () => { simulate(); return waitForIt(() => result())}; const _5 = () => { simulate(); return waitForIt(() => result())}; const _6 = () => { simulate(); return waitForIt(() => result())}; const _7 = () => { simulate(); return waitForIt(() => result())}; const _8 = () => { simulate(); return waitForIt(() => result())}; const _9 = () => { simulate(); return waitForIt(() => result())}; const _10 = () => { simulate(); return waitForIt(() => result())}; const _2_val = await _2(); const _3_val = await _3(); const _4_val = await _4(); const _5_val = await _5(); const _6_val = await _6(); const _7_val = await _7(); const _8_val = await _8(); const _9_val = await _9(); const _10_val = await _10(); const __text = new Set([_1.text, _2_val.text, _3_val.text, _4_val.text, _5_val.text, _6_val.text, _7_val.text, _8_val.text, _9_val.text, _10_val.text]); const __h1 = new Set([_1.h1, _2_val.h1, _3_val.h1, _4_val.h1, _5_val.h1, _6_val.h1, _7_val.h1, _8_val.h1, _9_val.h1, _10_val.h1]); assert(__text.size === 2 && __h1.size === 1, "When the GameOfChance component is first mounted to the DOM and each time the button is clicked thereafter, a single h1 element should be returned that randomly renders either You Win! or You Lose!."); }; ' ```
## Challenge Seed
```jsx class Results extends React.Component { constructor(props) { super(props); } render() { return (

{ /* change code here */ }

) }; }; class GameOfChance extends React.Component { constructor(props) { super(props); this.state = { counter: 1 } this.handleClick = this.handleClick.bind(this); } handleClick() { this.setState({ counter: 0 // change code here }); } render() { let expression = null; // change code here return (
{ /* change code below this line */ } { /* change code above this line */ }

{'Turn: ' + this.state.counter}

); } }; ```
### After Test
```js console.info('after the test'); ```
## Solution
```js // solution required ```