Skip to content

Commit 18dd6d8

Browse files
author
Rudy
committed
Code for Task 1 fixed and code for Task 2 created
1 parent ce92942 commit 18dd6d8

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Task1.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// This code works because the implicit type conversion with the - turns "5" into a number
2+
let result = "5" - 2;
3+
console.log("The result is: " + result);
4+
5+
// This code was returning valid because the value was a string, which made the value truthy. Removing the quotations changed it from a string to boolean.
6+
let isValid = Boolean(false);
7+
if (isValid) {
8+
console.log("This is valid!");
9+
}
10+
11+
//This code was returning 255 because the value of age was a string. Implicit type conversion will not happen with the +, so Number () was required to cause an explicit type conversion.
12+
let age = "25";
13+
let totalAge = Number(age) + 5;
14+
console.log("Total Age: " + totalAge);

Task2.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
let cookies = "10"
2+
let people = 2
3+
let math = (cookies / people);
4+
console.log("The number of cookies per person is: " + math);
5+
console.log("Type for variable cookies before implicit conversion is " + typeof cookies)
6+
7+
let value = null
8+
console.log("Before explicit conversion result: " + value)
9+
console.log("Type is " + typeof value)
10+
11+
let valueConvert = null;
12+
let toNumber = Number(valueConvert)
13+
console.log("After conversion result is: " + toNumber)
14+
console.log("Type is " + typeof Number(valueConvert))

0 commit comments

Comments
 (0)