Data Types - Exercise 2

Question 1: Create a Symbol Label

Create a Symbol using the supplied description and return its description.

Expected output: "ticket" (print this with console.log)

javascript

function symbolLabel(label) {
  // Write your solution here
}

console.log(symbolLabel("ticket"));

Question 2: Compare New Symbols

Create two Symbols using the supplied description and return an object containing their description and whether they are strictly equal.

Expected output: {"description":"id","equal":false} (print this with console.log)

javascript

function sameNewSymbols(label) {
  // Write your solution here
}

console.log(sameNewSymbols("id"));

Question 3: Read an Object Field

Return the city property of the supplied object.

Expected output: "Kyoto" (print this with console.log)

javascript

function readCity(place) {
  // Write your solution here
}

console.log(readCity({"city":"Kyoto"}));

Question 4: Create a Product Record

Return an object with name and price properties using the supplied arguments.

Expected output: {"name":"Pen","price":3} (print this with console.log)

javascript

function makeProductRecord(name, price) {
  // Write your solution here
}

console.log(makeProductRecord("Pen", 3));

Question 5: Check for a Callable Value

When enabled is true, create a function; otherwise use the supplied text. Return whether the resulting value has typeof "function".

Expected output: true (print this with console.log)

javascript

function isCallableValue(enabled, text) {
  // Write your solution here
}

console.log(isCallableValue(true, "hello"));

Question 6: Add a Numeric String

Convert the second argument to a number and return the sum.

Expected output: 15 (print this with console.log)

javascript

function addNumericText(amount, text) {
  // Write your solution here
}

console.log(addNumericText(7, "8"));

Question 7: Join as Text

Return both supplied values joined as strings, without a separator.

Expected output: "56" (print this with console.log)

javascript

function joinAsText(left, right) {
  // Write your solution here
}

console.log(joinAsText(5, 6));

Question 8: Convert a Flag to Number

Explicitly convert the supplied boolean to a number and return it.

Expected output: 1 (print this with console.log)

javascript

function flagAsNumber(flag) {
  // Write your solution here
}

console.log(flagAsNumber(true));

Question 9: Compare Without Coercion

Return whether the supplied values are strictly equal.

Expected output: false (print this with console.log)

javascript

function strictlyMatches(left, right) {
  // Write your solution here
}

console.log(strictlyMatches(5, "5"));

Question 10: Parse a Decimal Price

Convert the supplied decimal string to a number and return it.

Expected output: 19.75 (print this with console.log)

javascript

function parseDecimalPrice(text) {
  // Write your solution here
}

console.log(parseDecimalPrice("19.75"));