JavaScript: Type casting
Use conversion functions to explicitly change a value's type.
Number('42'); // => 42
String(42); // => '42'
Boolean(0); // => false
Boolean('hi'); // => trueInstructions
Given temperature = 36.6, truncate the decimal part, convert to string, and print 36 °C.
Tips
If you've reached a deadlock it's time to ask your question in the «Discussions». How ask a question correctly:
- Be sure to attach the test output, without it it's almost impossible to figure out what went wrong, even if you show your code. It's complicated for developers to execute code in their heads, but having a mistake before their eyes most probably will be helpful.
JavaScript: Type casting
Use conversion functions to explicitly change a value's type.
Number('42'); // => 42
String(42); // => '42'
Boolean(0); // => false
Boolean('hi'); // => trueInstructions
Given temperature = 36.6, truncate the decimal part, convert to string, and print 36 °C.
Tips
If you've reached a deadlock it's time to ask your question in the «Discussions». How ask a question correctly:
- Be sure to attach the test output, without it it's almost impossible to figure out what went wrong, even if you show your code. It's complicated for developers to execute code in their heads, but having a mistake before their eyes most probably will be helpful.
Your exercise will be checked with these tests:
// @ts-check
import { expect, test, vi } from 'vitest';
test('data types casting', async () => {
const consoleLogSpy = vi.spyOn(console, 'log');
await import('./index.js');
const firstArg = consoleLogSpy.mock.calls.join('\n');
expect(firstArg).toBe('36 °C');
});Teacher's solution will be available in:
20:00
