Posts

Showing posts from December 6, 2018

In crystal Why do I need to do matches.try &.[0]

Image
up vote 0 down vote favorite Here's some code: matches = //([a-z]+)/(d+)/state/([a-z]+)/.match(address) # line 1 puts matches[0]? # line 2 puts matches.try &.[0] # line 3 matches datatype is (Regex::MatchData | Nil) according to typeof . Yet, line 2, referring to matches[0] fails with a compilation error. And I don't understand line 3 at all! Could someone clarify? crystal-lang share | improve this question edited Nov 20 at 4:49 Cœur 17.2k 9 102 141

Capturing the text within an input field

Image
up vote 0 down vote favorite I'm having trouble figuring out what I'm doing wrong in this code. I'm simply trying to set the user's input for username and password and store them in their respective variables. For some reason the variables are always and empty string. Could someone tell me where I'm going wrong? HTML <body> <main> <h1>Login Form</h1> <form> <label for="username">Username:</label> <input type="text" name="username" id="username"> <label for="password">Password:</label> <input type="text" name="password" id="password"> <button id="submitButton" type="button">Submit<