scrimba
Helen Chong's JavaScriptmas 2023 Solutions
Helen Chong's JavaScriptmas 2023 Day 4 solution
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Helen Chong's JavaScriptmas 2023 Day 4 solution
AboutCommentsNotes
Helen Chong's JavaScriptmas 2023 Day 4 solution
Expand for more info
index.js
run
preview
console
/** uncomment one of these **/
// import OpenAI from "openai"
import { HfInference } from '@huggingface/inference'

const apiKey = process.env.HUGGINGFACE_TOKEN
const hf = new HfInference(apiKey)

async function getChristmasJoke() {
const prompt = 'Tell me a one-line Christmas joke'

const result = await hf.textGeneration({
model: 'tiiuae/falcon-7b-instruct',
inputs: prompt,
})
// const christmasJoke = result.generated_text
const generatedText = result.generated_text
const christmasJoke = generatedText.substr(prompt.length)

return christmasJoke
}

document.getElementById('window-container').addEventListener('click', async function () {
/**
* 🎄 Challenge:
* 1. When clicked, the doors should open
* to reveal a festive joke.
*
* 🎁 hint.md for help!
**/
document.querySelector('.left-door').style = "animation: left-open 0.3s forwards"
document.querySelector('.right-door').style = "animation: right-open 0.3s forwards"
document.querySelector('.joke-display').style = "animation: display-joke 0.3s forwards"

const jokeDisplay = document.getElementById('joke-display')
jokeDisplay.textContent = "Tell you a Christmas joke..."
jokeDisplay.textContent = await getChristmasJoke()
})
Console
/index.html
LIVE