Web Development Sessions

This space if for web development sessions
Recordings
// return beer can levels based on bonuses and price for each beer.
// Each level is of the form n^2 for n being the level number.

function beeramid(bonus, price) {
if (bonus <= 0 || price <= 0) return 0;
const totalCans = Math.trunc(bonus / price); // 4
// 🍻 beeramid 😅 level
const beeramidLevel = Math.trunc(Math.sqrt(totalCans)); // 2
let sum = 0;
for(let level = 1; level <= beeramidLevel; level++) {
sum += level ** 2;
if(sum > totalCans){
return level - 1;
}
}
return beeramidLevel;
}
Complete the function/method so that it takes a PascalCase string and returns the string in snake_case notation. Lowercase characters can be numbers. If the method gets a number as input, it should return a string.

Common Request headers to know

image.png
Sample code to show how to send a fetch request with Js.
const headers = new Headers();
headers.append("Accept", "application/json");
const req = new Request("https://icanhazdadjoke.com/");

fetch(req, {headers})
.then((response) => response.json())
.then((data) => {
console.log(data.joke);
})
.catch((error) => {
console.error("Error fetching joke:", error);
})
.finally(() => console.log("Done!"));


Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.