Lowest price ever! Learn Generative AI for 48% less!
Get my discount
+ 1

Let's fix this bug together 🥲

I'm trying to be checked a box when ${element.completed} has true value and unchecked when it has false value. One more thing is that I'm using API to show content on webpage so that I'm using javascript for that. hope you get my point...... https://www.sololearn.com/post/1690845/?ref=app

27th May 2022, 5:42 AM
Davinder Kumar
Davinder Kumar - avatar
4 Answers
+ 3
Davinder Kumar You were on the right track just need to put checked inside of the brackets and use && operator <td><input type='checkbox' ${element.completed && "checked"}></td>
27th May 2022, 7:02 AM
ODLNT
ODLNT - avatar
+ 3
Davinder Kumar var checked = '' if (element.completed) { checked = 'checked'; } <input type = 'checkbox' ${checked} />
27th May 2022, 6:44 AM
A͢J
A͢J - avatar
+ 3
Thanks you A͢J Ipang ODLNT your logic works well.
27th May 2022, 7:16 AM
Davinder Kumar
Davinder Kumar - avatar
+ 2
Your ternary operation has no `else` block, but then again, adding an `else` block didn't seem to help, except where the ternary condition and its results is moved within the {} guard. `<td><input type='checkbox' ${element.completed ? 'checked' : ''}/></td>`;
27th May 2022, 6:59 AM
Ipang