mardi 4 février 2020

Javascript - Numbers showing as NaN and object undefined

I am creating a project for school, and I am having an issue (or I wouldn't have asked the question). I am trying to make a comment generator for a program we use, and I am having an issue with numbers. I originally got object undefined after doing the math when I used the block of code below:

totalPages = toString(totalPages);
pagesLeft = toString(pagesLeft);
pph = toString(pph);
hour = toString(hour);
minute = toString(minute);
weekTG = toString(weekTG);

Then, I tried using the Number function when I got the values from the HTML inputs:

var totalPages = document.getElementById("totalPages");
var startPage = document.getElementById("startPage");
var endPage = document.getElementById("endPage");
totalPages = Number(totalPages);
startPage = Number(startPage);
endPage = Number(endPage);

When I used the above method, I got NaN. I also tried using parseFloat but that did not work out. Could I have some help? If you would like to look at my code further, you can look here in script.js. EDIT: The output is currently in the console, just to clear up any future confusion.




Aucun commentaire:

Enregistrer un commentaire