Tell us what’s happening:
Hi all,
I’ve gotten this to work by explicitly calling the .value method in my if statements but was curious as to why it doesn’t work if I do so by throwing it in a variable?
Any help is greatly appreciated! I just want to make sure I understand what’s happening here. Also if I am going about this the wrong way with the code that works please let me know.
Your code so far
/* file: script.js */
const userInput = document.getElementById('number');
const convertBtn = document.getElementById('convert-btn');
const result = document.getElementById('output');
// Created to keep from multiple .value method calls
const userInputValue = userInput.value;
// input validation
// only works for both when I explicitly use .value on both input references
const inputValidation = (input) => {
if (input === '') {
result.innerText = 'Please enter a valid number';
return console.log(parseInt(input));
} else if (parseInt(input) <= -1) {
result.innerText = 'Please enter a number greater than or equal to 0';
}
};
// Does not trigger else if - if I use userInputValue
convertBtn.addEventListener('click', () => {
inputValidation(userInputValue);
})
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Challenge Information:
Build a Roman Numeral Converter Project - Build a Roman Numeral Converter