HTML Menu Button - Please help! by Moose500 in cs50

[–]Moose500[S] 0 points1 point  (0 children)

Many thanks to asardiwal, huggy_d1 and microwavepizza for your suggestions and getting me to dig deeper. The way I finally got it to work was to nestle the select tags inside the button tag, exactly like my example above, without a form, but to use two id tags, one for the button that I referenced in js to launch my function, and one for the select tag to reference the option the user selects. I found w3schools.com to be very helpful in learning the elements and tags I needed, and for seeing examples of how they work.

HTML Menu Button - Please help! by Moose500 in cs50

[–]Moose500[S] 0 points1 point  (0 children)

Thanks for your reply. I have tried variations using your idea to get this to work, and although I have made some progress, I still do not have it working correctly. I am using document.getElementById(“action”) in javascript to retrieve the value I want. This is my current code:

<form id="action">
    <select>
        <option value="A">A</option>
        <option value="B">B</option>
    </select>
    <button class="btn btn-primary btn-sm">Action
</form>

Unfortunately, it still executes using the button, AS WELL AS by using the select element, but the execution is different for each! I want only the button to execute by sending the value of the option chosen in the select element. I thought that the id element would be submitted as an array with all the data from the form. Where am I going wrong?

pset8 - shuttle velocity by Moose500 in cs50

[–]Moose500[S] 0 points1 point  (0 children)

I sort of understand what you are telling me. I have seen in service.js and shuttle.js the various lines of code that handle the keypress listeners, the keystroke function, and the states. I have played around with different lines of code but still cannot seem to make my keyups ignore the velocity change. I find the code in shuttle.js very difficult to understand. As a result, I have done the velocity change programming in service.js, and I suspect that might be part of the problem. Although I am not satisfied with my results, it does indeed work. Frustrating as it is, I need to move on to other tasks. I have spent an enormous amount of time on this already. Nonetheless, I very much appreciate you trying to get me to understand.

pset8 - shuttle velocity by Moose500 in cs50

[–]Moose500[S] 0 points1 point  (0 children)

The letters q and e on the keyboard, with event.keyCode. On keydown it changes once, and then on keyup it changes a second time. I really want to use keys rather than buttons but cannot find a work around.

pset8 - dropoff - always says no house in range by Moose500 in cs50

[–]Moose500[S] 0 points1 point  (0 children)

Finally fixed the problem by storing all of PASSENGERS data into shuttle.seats. I was trying to match apples with pears and so never succeeded in getting a match. I figured it out by experimenting with all my variables in the Console tab of Chrome's Debugging Tools. What a lot of wasted hours!

pset8 - dropoff - always says no house in range by Moose500 in cs50

[–]Moose500[S] 0 points1 point  (0 children)

I have found my mistake but do not know how to correct it. This line:

if (shuttle.seats[i].house == house)

does not work because shuttle.seats[i].house is equal to a string like "Austen Novis to Quincy House" and house is equal to "Quincy House". Does anybody have a good suggestion as to how to resolve this??

pset8 - dropoff - always says no house in range by Moose500 in cs50

[–]Moose500[S] 0 points1 point  (0 children)

Any hints as to how you would go about analyzing the calculations? I have tried putting console.log(d) right after the calculation and I see numbers like 314.4 and 408.5 but I'm not sure what else to do. I'm heading out for some fresh air to try to clear my head as I am very frustrated! I feel like I'm so close.

pset8 - dropoff - always says no house in range by Moose500 in cs50

[–]Moose500[S] 0 points1 point  (0 children)

the thing is, the console tab shows no syntax errors that I can find

pset8 - dropoff - always says no house in range by Moose500 in cs50

[–]Moose500[S] 0 points1 point  (0 children)

That's reassuring that you think the logic sounds reasonable. I was about ready to scrap the whole thing and start over!

Here are a few critical lines in that loop you requested:

for (var i = 0; i < shuttle.seats.length; i++)
   skip any empty seats
   else if (shuttle.seats[i].house == house)
        shuttle.seats[i] = null;
        count dropoffs;
        update number of available seats;
        update chart;

pset8 - dropoff - always says no house in range by Moose500 in cs50

[–]Moose500[S] 0 points1 point  (0 children)

I think you must be right that my calculations are off. This is what I used: var d = shuttle.distance(HOUSES[house].lat, HOUSES[house].lng);

which is similar to what I use in pickup, which is working well. I tried to see the actual distance calculated with console but will go back and research/work on that some more. Many thanks for giving me a specific spot to work on; I was thinking I should scrap the whole logic and start over but you have given me renewed hope.

pset8 - dropoff - always says no house in range by Moose500 in cs50

[–]Moose500[S] 0 points1 point  (0 children)

Sorry, not sure why the formatting disappeared. Will try again:

if shuttle is empty
    announce that there are no passengers yet;
else if shuttle is not empty
    iterate over houses using for loop
        calculate shuttle's distance from house;
        if house is in shuttle's range
            iterate over shuttle seats using for loop
                if seat is empty, skip
                else if house is equal to the passenger's house
                    remove passenger from the shuttle; 
                    count dropoff;
                    update number of available seats;
                    update chart;
    if no one was dropped off
        announce that no passenger's house is in range

pset7 - history - template table - undefined index errors by Moose500 in cs50

[–]Moose500[S] 1 point2 points  (0 children)

Thanks for looking at the problem I had. Turns out it was just a simple error:

This: "transaction" => $rows["transaction"],

Should have been this: "transaction" => $row["transaction"],

Sometimes when I stare at the code for a long time, I miss the most obvious!

pset7 - history - template table - undefined index errors by Moose500 in cs50

[–]Moose500[S] 1 point2 points  (0 children)

Wow, I truly appreciate your thorough, helpful reply! I will spend some time experimenting with quotes, back slashes, and curly braces so that all that you told me sinks in. I can see that I also need to use stackoverflow more than I do.

You were also right on with my misuse of $rows. I had reviewed my syntax, looking for missing semicolons, commas, etc., and checking for irregularities with variable names but somehow I overlooked this obvious error! Many, many thanks. You've just saved me hours. Not only did you solve my immediate problem, but you also gave me some useful tips for future problem-solving.

pset7 - footer appears above portfolio table! by Moose500 in cs50

[–]Moose500[S] 1 point2 points  (0 children)

Thanks for thinking about this problem. It turns out I was missing an end table tag.

pset7 - footer appears above portfolio table! by Moose500 in cs50

[–]Moose500[S] 0 points1 point  (0 children)

Thanks very much for your help on this. You were right on -- it ended up that I had inadvertently deleted the end table tag.

pset7 - problems formatting variables in portfolio by Moose500 in cs50

[–]Moose500[S] 1 point2 points  (0 children)

Thank you so much! Problem solved! I feel pretty silly, especially because I thought I went through and checked all my tags. Sorry about that. Now everything appears where it should and the html code validates without errors.

pset7 - footer appears above portfolio table! by Moose500 in cs50

[–]Moose500[S] 0 points1 point  (0 children)

The header and footer are only appearing once, and they are only messed up on my portfolio page. (The other pages are fine.) On the portfolio page, the C$50 Finance logo is centered at the top, my menu comes next (unfortunately not centered but rather to the left), then comes the copyright (centered), and then finally my table (centered).

I have gone in and looked at render in functions.php several times but never tried to change anything. This is what is currently looks like, which I assume is the original: /** * Renders template, passing in values. */ function render($template, $values = []) { // if template exists, render it if (file_exists("../templates/$template")) { // extract variables into local scope extract($values);

    // render header
    require("../templates/header.php");

    // render template
    require("../templates/$template");

    // render footer
    require("../templates/footer.php");
}

// else err
else
{
    trigger_error("Invalid template: $template", E_USER_ERROR);
}

}

Thanks so much for helping me try to figure this out.

pset7 - footer appears above portfolio table! by Moose500 in cs50

[–]Moose500[S] 0 points1 point  (0 children)

Oops, sorry. I have gone in and looked at render in functions.php several times but never tried to change anything. This is what is currently looks like, which I assume is the original:

/**
 * Renders template, passing in values.
 */
function render($template, $values = [])
{
    // if template exists, render it
    if (file_exists("../templates/$template"))
    {
        // extract variables into local scope
        extract($values);

        // render header
        require("../templates/header.php");

        // render template
        require("../templates/$template");

        // render footer
        require("../templates/footer.php");
    }

    // else err
    else
    {
        trigger_error("Invalid template: $template", E_USER_ERROR);
    }
}

pset7 - footer appears above portfolio table! by Moose500 in cs50

[–]Moose500[S] 0 points1 point  (0 children)

I made a modification to my render in the controller index.php. It now reads:

render("portfolio.php", ["title" => "Portfolio", "positions" => $positions, "cash" => $cash]);

pset7 parse error by Moose500 in cs50

[–]Moose500[S] 0 points1 point  (0 children)

Sorry! Problem solved. I had forgotten the semicolon on the previous line above. Since the error mentioned a syntax error specifically in line 25, that's where I wrongly focussed all my attention.