So, I'm trying to read the input <textarea> , dividing it into separate words, and then check each word if it is equal to the word in the list of keywords.
I finished the code, and when I tested it, it did not work. When I debugged it, I saw that when it compares a string from a <textarea> string and a constant that looks the same, it considers them unequal.
I tried to take a string from <textarea> (in the same way, copying it) and compared it to a constant string statically, and then it became true.
If you know what the problem is, I will be glad to hear. Thanks.
Code:
function run() { debugger; code = document.getElementById("codeArea").value; cleanDots(); words = code.split(" "); compile(); } function compile() { for (i = 0; i < words.length; i++) { var w = words[i]; if (w == "test") alert("test - true"); } } function cleanDots() { for (var j = 0; j < code.length; j++) { if (code.charAt(j) == ".") { var p1 = code.substring(0, j); var p2 = code.substring(j + 1, code.length); code = p1 + " " + p2; } } }
HTML:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>דוס סקריפט סביבת פיתוח</title> <style type="text/css"> body{ padding: 0; margin: 0; } textarea{ width: 95%; padding: 10px; height: 700px; text-align: right; float: right; } button{ width: 95%; padding: 10px; text-align: center; float: right; background-color: green; } </style> </head> <body> <textarea id="codeArea"> </textarea> <button id="submit" onclick="run()">הרץ</button> <script src="compiler.js"></script> <script src="methods.js"></script> </body> </html>
source share