Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

i cant clear one of two inputs

i cant clear name input
when i go into strict mode console say: "Cannot create property ‘value’ on string ”"

    const number = document.getElementById("number").value;
    const name = document.getElementById("name").value;

    console.log(name)
    console.log(number)

    if (name.trim() && number.trim()) {
        let contact = {
            name,
            number
        };
        renderContact(contact);
        console.log(contacts);
        contacts.push(contact)
    }
    // clearInput(number, name);
    this.name.value = '';
    this.number.value = '';
};

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Your "name" and "number" is not DOM elements. There’s their values like: "Hello, World" and other. String is primitive type and you can’t define properties in prototype in strict mode.

const numberInput = document.getElementById("number")
const nameInput = document.getElementById("name")

const name = numberInput.value
const number = numberInput.value

if (name.trim() && number.trim()) {
    let contact = {
        name,
        number
    };
    renderContact(contact);
    console.log(contacts);
    contacts.push(contact)
}
// clearInput(numberInput, nameInput);
nameInput.value = '';
numberInput.value = '';

};

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading