Code & Coffee Blog

Sophies Code & Coffee

Learn & Brew New Ideas


JavaScript Loops: Stirring Up Iterations

Challenge: Write a loop that prints numbers 1 to 10.

Loops are like stirring your coffee – repetitive but necessary...

// JavaScript loop example
for (let i = 1; i <= 10; i++) {
    console.log(i);
}

This loop iterates from 1 to 10, printing each number...

CSS Flexbox: Aligning Your Ingredients

Challenge: Create a simple layout with three divs, aligned horizontally and centered.

Flexbox is like arranging cups on a tray...

/* CSS Flexbox example */
.container {
    display: flex;
    justify-content: center;
    align-items: center;
}

The above CSS centers the content horizontally and vertically...

Python Functions: Brewing Reusability

Challenge: Write a function that calculates the total cost of a coffee order with tax.

Functions in Python are like coffee recipes – reusable...

# Python function example
def calculate_total(price, tax_rate):
    return price + (price * tax_rate)

This function calculates the total price including tax...

Reversing a String in Python

In this Python code snippet, we demonstrate a simple function to reverse a string. This can be useful for various text manipulation tasks.


# Python snippet to reverse a string
def reverse_string(s):
    return s[::-1]

print(reverse_string("Hello, World!"))
        

Keep track of Code & Coffee for more coding tips!

Follow us on X | facebook