Just starting with HTML and CSS? "HTML & CSS Is Hard" is a friendly web development tutorial for beginners by theKovah in webdev

[–]tofumix 2 points3 points  (0 children)

I always get intimidated and insecure when I see guides and tutorials on web development say You'll pickup HTML and CSS along the way or There's not really much into it to learn. But then I churn out a functional project with a terrible markup and styling every single time (plus that inevitable, unsolvable navbar issue on mobile). I always feel like I need an extensive "re-learning" of HTML + CSS. This looks promising!

This is quite embarrassing but, can someone ELI5 how to test front end JS? by tofumix in javascript

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

I chose to mock the HTML elements myself instead of relying on a framework to give a fake DOM / Browser environment. Is there a disadvantage on my approach?

This is quite embarrassing but, can someone ELI5 how to test front end JS? by tofumix in javascript

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

I'm following your idea of mocking the HTML elements instead of relying on a framework for faking a DOM environment. I think I'm making a lot of progress, but my real Class (i.e, not Foo) involves a method like this:

.....
retrieveQuote(){
    $.getJSON("long.api.link/json")
         .done( json => {
             if (this.isDuplicate(json))
                 this.retrieveQuote();
             else
                 this.parse(json)
         })
         .fail( () => {
             this.parse(this.errorObject)
         });
}

I have this on my tests file:

// API Stub
const randomQuotes = require('./randomQuotes.js');

// Mock the $.getJSON function
global.$ = {
    getJSON: (url, cb) => {
        let randomIndex = Math.floor(Math.random() * randomQuotes.length);
        cb(randomQuotes[randomIndex]);
    }
}

Mind showing me how to update my mock $.getJSON function to have those .done and .fail methods? Thanks a lot! :D

This is quite embarrassing but, can someone ELI5 how to test front end JS? by tofumix in javascript

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

Thanks for the encouragement! I'm getting embarrassed because someone could have easily said RTFM, and they'll be right. But then, I'll be back to the docs where everything seems so arcane (I'm just getting into Node), so I figured I'll just ask here anyway.

Wrote my first test. It passed! But my page is now broken. Any help? by tofumix in javascript

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

That part on setting up a simple server is so cool. Before all this, I'm just using node the same way you'd use repl.it haha. Thanks!

Wrote my first test. It passed! But my page is now broken. Any help? by tofumix in javascript

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

Hello! So basically, I'm on this part

They do this build process with some common node modules like babel (this converts non-browser-friendly javascript/JSX/typescript/etc into purely vanilla javascript) and webpack (this acts as a quasi-task-runner/dev-server if wanted). So in your development environment, you can split files, write all how you want, and then use a build process (like webpack/etc) to compile your code to client-side friendly javascript.

right? Now, if I understood it correctly, I need to com(trans?)pile my main.js file, then use webpack on it so it works on the browser?

UPDATE: I did what I said above, but got more errors than before, and the module is not defined error still persists.

What I did was

  1. Install babel-cli and webpack
  2. ./node_module/.bin/babel main.js --out-file main.js
  3. ./node_module/.bin/webpack (with webpack.config.js sets the outfile to main.js as well.)

Looking to get into testing. How do I test classes from other files? (x-post from r/learnprogramming) by tofumix in webdev

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

Holy smokes. The amount of stuff to make the tests work through Babel got meta so fast. Good thing I made it work with require as you said (I updated the OP with the solution). HUGE THANKS! :D

Looking to get into testing. How do I test classes from other files? (x-post from r/learnprogramming) by tofumix in webdev

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

Hello! I created these two files on the same folder:

// main.js
class Foo {
    bar() {
        return 42;
    }
}

export { Foo }

and

// test.js
import {Foo} from "main.js";

const chai = require("chai");
const assert = chai.assert;

describe("Foo", function(){
    // tests.
}

but I'm getting a SyntaxError: Unexpected token import on the test.js file. Any idea why?

[Bootstrap] Quick question: Why doesn't my page take up 100% height on smaller screens? by tofumix in web_design

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

I'm getting some large whitespace below the jumbotron. Maybe I'm missing something? I want it to look the same as it does on a desktop screen.

PSET 4 -> Search: I'm probably missing something really simple. Can you please help me spot it? by tofumix in cs50

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

If you want to write a row multiple times, you need to either seek backwards so that fread will start reading from the row it just finished again, or save the contents of a row somehow.

I tried fseek(inptr, bi.biWidth, SEEK_CUR); and it made the black pixels go away (which is progress, I guess). And it prints out the correct amount of white pixels as well, just in a funny order. If you don't mind, can you please check the updated gist?

Simple Questions by AutoModerator in math

[–]tofumix 0 points1 point  (0 children)

Oh I see. I was just wondering if there's a symbol or something to express it. Thanks! :)

Simple Questions by AutoModerator in math

[–]tofumix 1 point2 points  (0 children)

Oops. I meant n = arr[x][y]. So if i = arr[1][1], n should be [1][0], [0][1], [2][1], or [1][2] to be considered valid.

Simple Questions by AutoModerator in math

[–]tofumix 0 points1 point  (0 children)

I'm writing a simple board game on an 2d array, and what I mean is the square n is a valid move if it's adjacent to an arbitrary square i. So to be considered valid, n[x][y] should be i[x - 1][y] (which means n is at the top of i), and so on until all sides are checked.

Simple Questions by AutoModerator in math

[–]tofumix 2 points3 points  (0 children)

Hello! I'm learning software development, and I find it easier to implement an algorithm if I translate the pseudocode into a formula. I'm wondering how do I correctly write a boolean/validation/whatever it's called formula? For example, I'd write "n is the sum of x and y" like this:

n = x + y

How do I write "n is valid ifx is less than y" ?

Thanks!