0

I attempted the following task but i am stuck on defining a boolean:

Define a function getWalletFacts that receives wallet, an object.

getWalletFacts should return a sentence stating the wallet’s color and cash state.

My attempted code

const hascash = Boolean();

let wallet ={
    color:"",
    hascash:true||false,
    write: function(sentence){
        console.log(sentence);
    }
};
function getWalletFacts(wallet){
    let sentence= "my wallet is " + wallet.color+ " and  " + wallet.hascash; 
    return sentence;
}

whenever i check my answer it tells me that hascash is undefined i.e

    Expected: "My wallet is Black and has cash"
        Received: "my wallet is Black and  undefined"

from my understanding of the question hascash accepts a boolean

Given example

const wallet = {
    color: "Black",
    hasCash: true
};

getWalletFacts(wallet); // => 'My wallet is Black and has cash'

const wallet2 = {
    color: "Grey",
    hasCash: false
};

getWalletFacts(wallet2); // => 'My wallet is Grey and does not have cash'
12
  • 3
    How are you calling getWalletFacts? Commented Sep 13, 2022 at 18:29
  • 1
    wallet.hascash won't evaluate to 'has cash'; your sentence would read "My wallet is Black and true." Also, what is const hascash = Boolean(); for? You don't reference it. Commented Sep 13, 2022 at 18:40
  • What's the point of hascash:true||false? That's the same as hashcash: true. Commented Sep 13, 2022 at 19:31
  • @mykaf Thanks for the feedback. So what should i do to make the sentence read "My wallet is Black and has cash"or "My wallet is Black and has no cash" Commented Sep 13, 2022 at 20:37
  • @James GetwalletFacts is called by the software when i submit my work ,the system check if i'm meeting the questions criteria. Commented Sep 13, 2022 at 20:41

2 Answers 2

2

It's hasCash, not hascash -- JavaScript is case-sensitive.

You also need a conditional to turn the true/false values into proper English.

function getWalletFacts(wallet) {
  let sentence = "my wallet is " + wallet.color + " and " + (wallet.hasCash ? "has cash" : "does not have cash");
  return sentence;
}

const wallet = {
    color: "Black",
    hasCash: true
};

console.log(getWalletFacts(wallet)); // => 'My wallet is Black and has cash'

const wallet2 = {
    color: "Grey",
    hasCash: false
};

console.log(getWalletFacts(wallet2)); // => 'My wallet is Grey and does not have cash'

Sign up to request clarification or add additional context in comments.

2 Comments

Could you explain a bit more about the conditional to turn the true/false values into proper English
0
function getWalletFacts(wallet) {
let money = " ";
if (wallet.hasCash === true) {
    money = "has cash";
}   else {
    money = "does not have cash";
}
let sentence = "My wallet is " + wallet.color + " and " + money;
return sentence;

}

1 Comment

The problem in the code of the user who asked the question is case sensitive of hasCash, your code is just a different style

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.