#.

1 messages · Page 1 of 1 (latest)

south totem
#

you want the red text to be indented to where the blue text is?

#

what part are you confused on?

#

like how to compare 2 strings?

#

oh

#

well for the last part you can just compare them after removing the newlines

#

and the thing you were asking about before you can just iterate through the file at the same time as you iterate through organized lines

#

do you have to tell if lines are partially correct?

#

oh

#

it's either all correct or all wrong?

#

oh ok

#

just get the entire string from the file

#

then get the entire string that you want to compare

#

remove the newlines

#

and compare them

#

how are you going to determine what textfile to use?

#

process arguments?

#

or something in the url?

#

or something you can type in

dense widgetBOT
#

@vernal sapphire

Godhero810 Uploaded Some Code
Uploaded these files to a Gist
south totem
#

oh

#

unrelated

#

but you know on line 34 you are using bitwise OR?

#

oh ok

#

as long as you have a valid file and it works for one file it should work for any

#

or like the great majority of valid files at least

#

so are you able to have it work with the user supplied filename?

#

just load up the file with fs then

#

it should be very similiar to what you did with the chords

#

except you might not need to really parse it

dense widgetBOT
#

@vernal sapphire

Godhero810 Uploaded Some Code

Uploaded these files to a Gist
south totem
#

oh

#

yeah there is

#

but do you know like a relative url to it?

#

oh looks like the server file line 97 has you covered

#

do you got the idea of what you got to do now?

#

there is other ways but it's already written in the server code for you

#

where are the files going to be located in the file structure?

#

in the same directory as the js?

#

or in /songs/?

#

and will they be .txt extensions?

#

oh do you still have the code to make a post request from before?

#

I dunno if u had one before or not

#

yeah

#

at the bottom

#

when you change the userText and then press enter it doesn't update the song from the correct file?

#

sorry I edited what I said

#

lineWords = line.split(" ")

#

on that line you have the loaded lines

#

you can take it and add it to a structure if you want to use it again later

#

or you can just process it there

#

you can use the same code above it to get to the same parrt

#

this part

#

you said that was in another button right?

#

I was saying that you can use the same code to get the line by line by reusing the above code

#

sadly I gtg for now someone has been waiting on me I'll check in on here to see if you are making any progress

#

they are actually doing something for a bit

#

I can look at it for a bit longer

#

but solve puzzel can only be called after get puzzle has been?

#

cause you can just get the textContent from already filled in html

#

and compare it without the newlines to see if they are the same

#

you just need the areas where the text is

#

I am looking back at the code

#

check in your browser

#

is it in text-area?

#

yeah try textDiv.innerText to get the inside without the formatting

#

like after you have it filled out

#

like after the words are present on the page

#

then inside textDiv.innerText they should have the unformatted text

#

like roses are red violets are blue or w/e

#

cause you will have some kind of html in it in reality

#

like it might have <p> <span> stuff like that

#

yeah it should work

#

oh

#

that won't work

#

you use String.localeCompare()

#

like string1.localeCompare(string2)

#

file.txt is a file so you would have to load it up into a strong

#

string

#

you can just alter the file name

#

you said its based on some userinput right?

#

but also it's already in the server

#

to load from the songs folder

#

thats not the right code for what you are doing?

#

I don't remember seeing songFile

#

oh yeah

#

it has the file name in it

#

nah you need to do all the things before

#

with the http post

#

so that the server can give you back the json

#

you need to compare the response object.text

#

is that on the server?

#

it's like the client is asking the server for stuff

#

but you can't directly access variables from the server

#

you can just make requests to it

#

yeah it looks like

#

I don't think that will work cause songLines is an array of LInes

#

Lines

#

that just looks like the filename to me

#

but I'm not sure

#

try making a string and running a loop through responseObj.songLines

#

or use map

#

I can't get that to work for me

#

but if u can get it to work then u can use that

#

but you want to take in an array of words like ["Roses are", "Red violets", "are blue", " and so on"]

#

and get a single string like "Roses are Red violets are blue and so on"

#

it's in the response.songLines as an array

#

just merge the array

#

let mergedLines = responseObj.songLines.reduce((acc,x)=>acc+x+" ","")

#

you can try that

#

just to put the lines together

#

it will put the text into mergedLines

#

somewhere after the responseObj has been created

#

can u still access the responseObj like that?

#

I don't think so but you can try it

#

like still working

#

try console logging merged lines

#

see if you are getting what u are looking for

#

yeah thatsnot looking good

#

check problems

#

responseObj is probably not found

#

oh it's completely unrelated lol

#

its cause you had canvas 1 but it has nothing in it

#

it is empty

#

wait did u press the button though

#

when u console logged?

#

is this the server or the client?

#

thats not a js file?

#

this one?

dense widgetBOT
#

@vernal sapphire

Godhero810 Uploaded Some Code
Uploaded these files to a Gist
south totem
#

so maybe you should be looking in the browser console for the logging

#

yeah so you need that code that was above it

#

to get the request

#

you could just copy and paste it or put it in another function and call the function

#

yeah but you need the response text also

#

you need to make a request to get it all

#

I don't think you have access to this.responseText but you can try

#

yeah it was like all the stuff in handleGetPuzzle

#

.

#

that looks like it might be enough to log

#

try it out

#

I don't think u need the draw canvas part though

#

but I'm not sure

#

you don't need the for loop

#
 let responseObj = JSON.parse(this.responseText)
        //console.dir(responseObj) //pretty print response data to console.
        movingString.word = responseObj.text
      let mergedLines =  responseObj.songLines.reduce((acc,x)=>acc+x+" ","")
  console.log(mergedLines)```
#

its having a problem with the response

#

did u change something above?

#

where is the request code at?

#

says handleTimer isn't definted in eventListeners.js

#

it's working as intended?

#
#

you can just do this to change the css to correct or incorrect

#

you use js to manipulate the dom

#

oh I thought u said you had it working as intended

#

oh you need the open and send after it

#

you can't get the text yet

#

you got to get the request working

#

add the open and send parts from the working code

#

do you have userRequestJSON this defined

#

it was here

#

did u cut it out?

#

u also need this line

#

does it work now?

#

does the mergedlines show properly?

#

try writing something else

#

like try logging something else besides merglines

#

see how far it works successfully in the code

#

w/e u want

#

"here"

#

try console logging before the http request then

#

see if the issue is the request or not

#

are you sure that uncaught reference error is ok?

#

ok

#

is it logging anything?

#

just log anything to see if it logs at all

#

you are just checking like where the problem is occuring

#

like does the button not work?

#

does the response part not work

#

does the mergedlines not work

#

is the button doing anything?

#

to compare you just run an if statement

#

when u have both strings

#

its if(string1.localeCompare(string2)===0)

#

so you should be set

#

are you going to append it all to a string then compare?

#

are you going to just run a loop on what you have

#

?

#

and u should still be able to get the text from textDiv.innerText for one of the strings to compare

#

let textDivString=textDiv.innerText

#

or you can just name it whatever you want

#

whats the other string going to be named?

#

where are you getting the text file string from?

south totem
#

you said this code you have works

#

so can you get it from here?

#

oh

#

I don't think you can compare strings like that

#

actually I just tested

#

it

#

maybe u can

#

maybe console.log what user text is and what linewords is

#

does that seem normal to you?

#

wait it says there is 7 entries

#

maybe it is empty

#

looks like it's empty

#

thats the text field that user text comes from and it's empty?

#

is that what is being used to compare?

#

let userText = document.getElementById('userTextField').value.trim();

#

for this line

#

which element is 'UserTextField?

#

that is the string you are comparing though

#

did you mean to use it to compare with the other string?

#

so when you ran the test did u type into the box to see if it was working?

#

I am confused about what strings you are trying to compare

#

is it input from the textbox?

#

are you trying to type into the box and compare that to something?

#

the stuff inside puzzle1.txt not the stuff inside the input box correct?

#

you are comparing the empty input boxthough

#

probably with fs

#

import fs from "fs" at the top

#

thats like the actual code

#

that is the million dollar question

#

you can use the relative file path

#

like it being in the same folder as you

#

or like in a folder that is in the same srea

#

area

#

you did it with the chords

#

to load from the songs folder

dense widgetBOT
#

@vernal sapphire

Godhero810 Uploaded Some Code

wait where

Uploaded these files to a Gist
south totem
#

I don't remember

#

I remember it had sister_golden_hair.txt in the code

#

or something like that

#

you can put the filename as a variable

#
import { readFileSync } from "fs"
function go()
{
    let userInput="sister_golden_hair.txt"
    let filename=`./songs/${userInput}`
    const data = readFileSync(filename,"utf-8")
console.log(data)
}
go();```js
#

thats the code to just read in a file and print it out

#

but it's based on whatever the file is gonna look like

#

is puzzle1 in the songs folder?

#

try console logging fileContent

#

also is linewords a single line?

#

and you are comparing if one line of the words is equal to all the lines?

#

so linewords is just one big block of text?

#

is it?

#

maybe console log it

#

oh yeah

#

the import

#

const fs = require('fs');

#

maybe try that

#

instead of the import

#

oh thats even worse

#

look back at how you did it before

#

with the filesystem

#

yeah thats np

#

there is more than one way to solve anything

#

what approach would you like to take

#

oh he did it on the server

dense widgetBOT
#

@vernal sapphire

Godhero810 Uploaded Some Code

i assume hes talking about this

Uploaded these files to a Gist
south totem
#

does his work?

#

cause that sounds like if the lines don't match it won't match

#

how did he make sure to make sure the entire text as a whole matches and not give false negatives when the lines don't match but it matches overall?

#

oh he put the words into an array?

#

oh yeah that makes sense

#

how to compare two arrays of words 1 at a time?

#

if you have the text like "Roses are red" and you run split on it

#

it will give you an array of words

#

is that what you are trying to do?

#

with fs?

#

you just do the readfile then split it

#

that I dunno

#

after you have them split

#

you just run every on one of them to check if each element is the same

#

ok

#

progress

#

thats good

#

nice

dense widgetBOT
#

@vernal sapphire

Godhero810 Uploaded Some Code

how would i compare them?

Uploaded these files to a Gist
south totem
#

wordDetailsArray .every((x,i)=>x===wordArray [i])

#

but it looks like they don't exist at the same time

#

cause of scopes

#

it's not really the best idea

#

but u can use var

#

but maybe u can just have the function return a value

#

or the array

#

what is wdwdww

dense widgetBOT
#

@vernal sapphire

Godhero810 Uploaded Some Code
Uploaded these files to a Gist
south totem
#

you can update the css

#

I forgot how you did it in your css

#

can u link that again?

#

document.getElementById("text-area").className="correct"

#

and document.getElementById("text-area").className="incorrect"

#

np

south totem
#

What's up

south totem
#

I don't know like a specific site other than youtube since there are many animations there and they draw out the problems but try making a new post I have seen people respond maybe with a bot command that might have some useful links