Skip to content

Instantly share code, notes, and snippets.

View tripdog's full-sized avatar
💭
meditating

Tom Phillips tripdog

💭
meditating
View GitHub Profile

A JSX Primer Module#76 🚀

hackmd-github-sync-badge

Defining an H1 conataining a string looks like the below snippet. It does look like a strange combination of JavaScript and HTML, but it's actually all JS.

const element = <h1>Hello, world!

Expressions in JSX can easily take HTML attributes:

@tripdog
tripdog / webdev_online_resources.md
Created June 12, 2021 20:32 — forked from bradtraversy/webdev_online_resources.md
Online Resources For Web Developers (No Downloading)
@tripdog
tripdog / args_as_array.md
Last active June 12, 2021 21:58
Access a Function's arguments as an Array

Function Arguments As An Array:

/*The 'arguments' of a function can be accessed with the arguments keyword. */

function sortedArgs() {
  console.log(Array.isArray(arguments));
  //false
 
@tripdog
tripdog / parameters.md
Last active June 12, 2021 22:00
Template Literals (parameters)

Passing Parameters To Fields In Template Literals

function dog_years(name, age) {
    return `${name} you are ${age*7} years old`
}
console.log(dog_years("lola", 16))

//passing names into fields (Bond, James Bond)
function introduction(first, last) {
@tripdog
tripdog / operators.md
Last active June 12, 2021 22:01
Operators (math)

Operators - Lots Of Math

function lotsOfMath(a, b, c, d){
    sum = a + b
    console.log(sum)
    minus = d - c
    console.log(d - c)
    console.log(sum * minus)
 console.log(minus%a)
@tripdog
tripdog / loops.md
Last active June 12, 2021 22:07
Basic For Loop Examples

Basic For Loop Examples

Count to 100 by only odd numbers

for (let x = 0; x < 100; x++){
    if ((x % 2) !== 0)
        console.log(x)
}

Count To 100 By 5

@tripdog
tripdog / conditionals.md
Last active June 12, 2021 22:10
Conditionals (if, if else)

Conditionals

If else

const lifePhase = (age) => {
    if (age <= 3) {
        return 'baby'
    } else if (age > 3 && age <= 12) {
        return 'child'
 } else if (age &gt; 12 &amp;&amp; age &lt;= 19) {
@tripdog
tripdog / package.md
Last active June 12, 2021 22:17
Add a start script to your package.json file to run parcel watch and browser-sync so you don't have to remember to do it.

Add Scripts To Package dot JSON To Run Parcel Watch and Browser-Sync

{
"scripts": {
    "start": "parcel watch app.js & browser-sync start --server --files '.'",
    "watch": "parcel watch app.js",
    "sync": "browser-sync start --server --files '.'"
  }
}
@tripdog
tripdog / truthyOrFalsy.md
Last active June 17, 2021 04:08
If the variable is truthy return true, else return false

If the variable is truthy, return true. If it is falsy return false.

function truthyOrFalsy(random) {
    return (random ?  "true" : "false") 
  
}
console.log(truthyOrFalsy(39))
@tripdog
tripdog / appendSum.md
Last active June 17, 2021 04:15
Take the last two numbers from an array, sum them, and append to the end of the array.

Take the last two numbers from an array, sum them, and append to the end of the array.

function appendSum(nums) {
    nums.push(nums[nums.length - 1] + nums[nums.length - 2]); 
    nums.push(nums[nums.length - 1] + nums[nums.length - 2]); 
    nums.push(nums[nums.length - 1] + nums[nums.length - 2]);
    return nums
}
console.log(appendSum([1, 1, 2]))