Programming basics 03: Expressions (simple maths)

Pubblicato il: 15 novembre 2023
sul canale di: Codersaurs
16
1

Today we’re going to be showing you how to get our program to do some simple mathematics. And as an added bonus, you’ll learn how to tell our favourite dinousaur how to write things to the screen.

----------------------------------------------------------------------------
Here is today's code snippet:
----------------------------------------------------------------------------

cs()
home()
pu()

function write_and_step(value_to_write) {
const FONT_SIZE = 1.5
const STEP_SIZE = 15
write(value_to_write, FONT_SIZE)
fd(STEP_SIZE)
}

write_and_step("Dinosaurs are cool!")

write_and_step(42)

const SOME_CONSTANT = 1234
write_and_step("Constant is " + SOME_CONSTANT)

const EGGS_PER_BOX = 6
const GOOD_EGGS_PER_BOX = EGGS_PER_BOX - 2
write_and_step("Eggs: " + GOOD_EGGS_PER_BOX)

const BOXES_PER_CRATE = 120
const GOOD_EGGS_PER_CRATE = BOXES_PER_CRATE * GOOD_EGGS_PER_BOX
write_and_step("Crate: " + GOOD_EGGS_PER_CRATE)

const SCORE_MATHS = 84
const SCORE_SCIENCE = 90
const SCORE_ENGLISH = 50
const SCORE_AVERAGE = (SCORE_MATHS + SCORE_SCIENCE + SCORE_ENGLISH) / 3
write_and_step("Average: " + SCORE_AVERAGE)

const RADIUS = 3
const PI = 3.1415927
const AREA = PI * RADIUS * RADIUS
write_and_step("Area: " + AREA)

const TEMP_FARENHEIT = 60
const TEMP_CELCIUS = (TEMP_FARENHEIT - 32) * 5 / 9
write_and_step(TEMP_FARENHEIT + " farenheit is " + TEMP_CELCIUS + " celcius")


In questa pagina del sito puoi guardare il video online Programming basics 03: Expressions (simple maths) della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Codersaurs 15 novembre 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 16 volte e gli è piaciuto 1 spettatori. Buona visione!