Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, coding guys,

So as you saw, loop() returns an:

Uncaught (in promise) SyntaxError: Unexpected end of input (at script.js:6:107)

And my code should perfectly run:

script.js
document.chatWrapper = document.getElementById("chat")
loopRun = true

function loop() {
	try {
		fetch("https://server.klasik.repl.co/msgs/read/", {"mode": "no-cors"}).then(function(resp) {return resp.json()}).then(function(json) {resp = json["msg"]})
	} catch (err) {
		delete resp
	}
	document.chatWrapper.style.height = document.chatWrapper.style.minHeight = document.chatWrapper.style.maxHeight = new String(window.innerHeight - document.querySelectorAll("nav")[0].clientHeight) + "px"
	document.chatWrapper.scrollTop = document.chatWrapper.scrollHeight
	// setTimeout(loopRun ? loop : function() {}, 1)
}

loop()

function onInputKeypress(e) {
	if (typeof e != "undefined") {
		if (e.keyCode == 13) { // Enter key
			var frame = document.createElement("iframe")
			frame.src = "https://server.klasik.repl.co/msgs/add/" + document.querySelector("body nav input").value + "/"
			document.querySelector("body nav input").value = String()
			document.activeElement.blur()
			document.body.appendChild(frame)
		}
	}
}

document.querySelector("body nav input").onkeyup = onInputKeypress


What I have tried:

                              
Posted
Updated 8-Jun-22 1:44am
Comments
Richard MacCutchan 7-Jun-22 12:21pm    
I think you need a semi-colon (;) at the end of each statement.
0x01AA 7-Jun-22 12:35pm    
Unfortunately js does not force one to add a semicolon for each statements. Only under some condition one have to do it :(
Richard MacCutchan 7-Jun-22 15:25pm    
That is why a did not put this as a solution.
Tyrunt.new("Rix") 7-Jun-22 12:44pm    
Doesn't work
Richard MacCutchan 7-Jun-22 15:26pm    
what doesn't work? If you try something and there is still a problem then please use the Improve question link above, and add complete details so people can try to help.

You need to remove the {"mode": "no-cors"} option from your fetch request.
no-cors
... In addition, JavaScript may not access any properties of the resulting Response.

If you leave the mode as no-cors and display the result of resp.text(), you will see that the response content is empty.

After removing the mode option, the response content will be returned correctly, and your resp.json() call will work.
 
Share this answer
 
Comments
Tyrunt.new("Rix") 9-Jun-22 10:53am    
Only worked one time...
What on earth is this:
JavaScript
document.chatWrapper.style.height = document.chatWrapper.style.minHeight = document.chatWrapper.style.maxHeight = new String(window.innerHeight - document.querySelectorAll("nav")[0].clientHeight) + "px"

It makes no sense at all. You can only have one equals in an assignment statement and you have 3.
 
Share this answer
 
Comments
Tyrunt.new("Rix") 9-Jun-22 10:49am    
It's a multiple assignment ( you probably know that you'll learn things any time ) , if you try something like a = b = c = "pew" and try to get a, b or c, you'll get "pew"
Dave Kreskowiak 9-Jun-22 11:04am    
I know what it is. I didn't know it was possible in Javascript. I only ever see it in C/C++ code. Frankly, I hate it. It's a horrible concept that never should have existed.
Tyrunt.new("Rix") 23-Jun-22 4:35am    
It shortens code :s
Dave Kreskowiak 23-Jun-22 9:12am    
I know that, because other languages have it. What it doesn't do is make your code more readable and debuggable, quite the opposite actually.
You're either missing a semicolon on a statement that requires it, or you've got mismatched double quote characters, parenthesis, square brackets, or curly braces. For example, you have an opening curly brace but no matching closing brace.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900