Build a temperature converter! The user types a Celsius value and the component immediately shows the same temperature in Fahrenheit.

The component must render an <input> element with the class celsius and a <p> element with the class fahrenheit. The paragraph text must be exactly Fahrenheit: N, where N is the converted value using the formula F = C * 9 / 5 + 32.

The component starts at 0 degrees Celsius, so the very first render must show Fahrenheit: 32. Every time the input fires an input event, read the new value, convert it, and update the paragraph.

Note that LWC templates cannot concatenate strings inline, so build the label in JavaScript with a getter and render {fahrenheitLabel} in the template. Use Number(event.target.value) so the arithmetic works on a number instead of a string.

Examples:

Initial render: <input class="celsius" /> <p class="fahrenheit">Fahrenheit: 32</p> Type 100 -> paragraph shows: Fahrenheit: 212 Type -40 -> paragraph shows: Fahrenheit: -40 Type 25 -> paragraph shows: Fahrenheit: 77
LWC

Preview

Press Run & Test to compile and preview your component.

Test results

Tests run automatically after each compile.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In