# Comments start with a hash symbol# VARIABLESx=5# Integery=3.14# Floating-point numberz="Hello, world!"# Stringis_true=True# Boolean# PRINTINGprint("Hello, world!")# Print a stringprint(x)# Print a variableprint(f"The value of x is {x}")# Print a formatted string# INPUTname=input("What is your name? ")# Get input from the user# CONDITIONALSifx>y:print("x is greater than y")elifx<y:print("x is less than y")else:print("x is equal to y")# LOOPSforiinrange(5):# Loop 5 timesprint(i)whilex>0:# Loop until x is 0print(x)x-=1# LISTSmy_list=[1,2,3]# Create a listmy_list.append(4)# Add an element to the end of the listprint(my_list[0])# Access an element by indexforiteminmy_list:# Loop over the listprint(item)# OBJECTSclassPerson:def__init__(self,name,age):self.name=nameself.age=agedefsay_hello(self):print(f"Hello, my name is {self.name} and I am {self.age} years old.")p=Person("John",30)p.say_hello()# Call a method on the objectprint(p.name)# Access an attribute of the object
// Comments start with double slashes// VARIABLESletx=5;// Integerlety=3.14;// Floating-point numberletz="Hello, world!";// StringletisTrue=true;// Boolean// PRINTINGconsole.log("Hello, world!");// Print a stringconsole.log(x);// Print a variableconsole.log(`The value of x is ${x}`);// Print a formatted string// INPUTletname=prompt("What is your name?");// Get input from the user// CONDITIONALSif(x>y){console.log("x is greater than y");}elseif(x<y){console.log("x is less than y");}else{console.log("x is equal to y");}// LOOPSfor(leti=0;i<5;i++){// Loop 5 timesconsole.log(i);}while(x>0){// Loop until x is 0console.log(x);x--;}// ARRAYSletmyArray=[1,2,3];// Create an arraymyArray.push(4);// Add an element to the end of the arrayconsole.log(myArray[0]);// Access an element by indexfor(letitemofmyArray){console.log(item);// Loop over the array}// FUNCTIONSfunctionsayHello(name){console.log(`Hello, ${name}!`);}sayHello("John");// Call the function// OBJECTSletmyObject={name:"John",age:30,hobbies:["reading","playing guitar"]};console.log(myObject.name);// Access a property by name// DOM MANIPULATIONletmyElement=document.getElementById("my-element");// Get an element by IDmyElement.innerHTML="Hello, world!";// Change the element's contentmyElement.style.color="red";// Change the element's style
;; Comments start with double semicolons;; VARIABLES(setqx5); Integer(setqy3.14); Floating-point number(setqz"Hello, world!"); String(setqis_truet); Boolean;; PRINTING(message"Hello, world!"); Print a string(message"%d"x); Print a variable;; INPUT(setqname(read-string"What is your name? ")); Get input from the user;; CONDITIONALS(if(>xy)(message"x is greater than y")(if(<xy)(message"x is less than y")(message"x is equal to y")));; LOOPS(dotimes(i5); Loop 5 times(message"%d"i))(while(>x0); Loop until x is 0(message"%d"x)(setqx(-x1)));; LISTS(setqmy-list'(123)); Create a list(add-to-list'my-list4); Add an element to the end of the list(nth0my-list); Access an element by index(dolist(itemmy-list); Loop over the list(message"%d"item));; OBJECTS(defclassperson()((name:initarg:name:typestring)(age:initarg:age:typeinteger)))(defunsay-hello(person)(message(concat"Hello, my name is "(orefpersonname)" and I am "(number-to-string(orefpersonage))" years old.")))(setqp(make-instance'person: