uh huh buddy I think you need to add function generate(length) { to the top, and the onclick attribute should be onclick="generate('length')" (replace the ‘length’ portion to your id)
Yeah, i’ve already added the function generate(length) { thing, i just didn’t copy-paste the code into my post correctly
And also these are my new logs after repeatedly trying to click the “generate” button: ReferenceError: passlenght is not defined at generate ReferenceError: passlenght is not defined at generate ReferenceError: passlenght is not defined at generate ReferenceError: passlenght is not defined at generate ReferenceError: passlenght is not defined at generate ReferenceError: passlenght is not defined at generate
good first step on looking at the logs for a hint about what’s going wrong.
one important thing here is when you look at your logs, make sure you know what messages are from things going wrong with the current code and what messages were from previous runs about problems that you’ve fixed already. we can tell here that things are getting mixed up because script execution should stop at the first error, so you shouldn’t be getting two runtime errors from a “straight-line” piece of code on one invocation. so perhaps we should only look at the bottommost error about one.split. that part of the code with var passlenght = ... .value; looks fine, if unusually spelled.
so what is it about one.split? in practice, most is not a function tends to be cases where the value is undefined or something. I think that’s the case here. I’m pretty sure you’ve made some typos in the line before. try running the code snippet in your post through a sufficiently powerful code beautifier to get some hints on what’s going on. here’s one such one: http://www.jsnice.org/
'use strict';
var passlenght = document.getElementById("lenght").value;
/** @type {number} */
var one = Math.random();
+Math.random();
+passlenght;
two = one.split("").reverse().join("");
split = two.split("");
three = split[1] + split[0] + split.slice(1).join("");
console.log(three);
look what’s happened on lines 5 and 6 (I think you’ll just have to count them out. thanks, code formatting). +Math.random(); and +passlenght; are separate statements, with the ; separating them from the var one = ... coming before. [side note: if you’re wondering why +xxx; is not a problem, it’s a unary plus Unary plus (+) - JavaScript | MDN, and it’s fine to have a statement that’s just an expression]
incidentally, this beautifier has also annotated the type of var one, which it’s a number. number don’t have a split method, so one.split is undefined. undefined is not a function, so you can’t call it.
to recap the lessons in this question:
find out which error messages are relevant to the current version of the code
if something’s wrong with the code syntax but there’s no syntax error, try using a code beautifier to visualize how the code is being parsed in a not-correct-yet-not-erroneous way
javascript allows some awkward things without crashing, so sometimes problem reporting gets delayed such that you end up with less relevant diagnostics. this you just gotta be aware of, and with experience, you’ll have some intuition of what problems lead to what error messages
anyway, if you don’t want feel like learning anything today, fix ...; + ... to be ... + ... and have a nice break