You are on page 1of 5

DHA Suffa University Department

of Computer Science SE1001L


Programming Fundamentals Lab
Fall 2023
Lab 01 Scratch Programming

Scratch Programming:
Scratch is block-like programming language to create visual program and also write code for
other innovative problems easily using visual block of codes.

With Scratch, you can program your own interactive stories, games, and animations.

Using Scratch, users can create online projects and develop them into almost anything by using a
simple block-like interface.

Scratch Environment:

Sprite: Is an actor in scratch programming which shows the result/output for the written block of
code in Script area.
Script Area: The area in which statement block dragged from Script block and drop to the script
area.

Statements Block or Scripts


Example 01
To move a sprite 10 step in forward direction

Task01 (degree.sb)
Create script to change the direction of sprite 15 degree in clockwise direction.

Example 02
To move a sprite 10 step in forward direction with when click condition

When Clicked is an event to execute the script by clicking on it.

Task02 (move.sb)
Create a script to move 50 steps

Example 03

Join the puzzle pieces

Task03 (thinking.sb)
Create script for join puzzle in which sprite think for problem solving and wait for 2 seconds
repeatedly three times.
Example 04

Ask user name from user


Task04 (hobby.sb)
Create a script to ask user for his hobby and spirit will show it for 5 seconds.

Example 05

Usage of Operators

Task05 (cube.sb)
Create script to take a number from user and print its cube.

Decision making Block: Decides whether certain criteria (condition) is true or not. If true it
executes if block otherwise it executed else block.

Example 06
Decision making Statement-checks whether you typed zero-(without else block)

Task06 (SpellCheck.sb)
Create script to ask name from user and check if its Pakistan then sprite said Pakistan for 5 sec using
if block.

Example 07
Decision making Statement -checks whether you typed a positive number or a negative number
(with else block)
Task07 (above100.sb)
Create script to ask string from user tell whether it’s greater than 100 or not.

Example 08

Repeat Block: Repeats itself until the number of times given.

Repeat Block

Task08 (MultiChange.sb)
Create script to ask number from user and check if its negative then play sound (mew) else play
drum (Hand clap) repeatedly 10 times.

Example 09
Forever Block: Repeats itself forever, it has no repetition limit defined.

Forever Block

Task09 (bounce.sb)
Create script to move sprite in any direction forever if it touches the any side of edge then
bounce and move.
Learning Assignment 01

Problem01 (signup.sb)
Take a user name, password and age as input and create account of the user if he/she is above 18 years.

Problem02 (login.sb)
Take a username and password as input and validate if password is equals to 12345 then login to the system.

Problem03 (change.sb)
Take a number as input if the number is less than 0 then change the color of sprite else change the position
of the sprite by 2 points by y.

Some useful links may help you in solving question s


 http://wiki.scratch.mit.edu/wiki/Move_()_Steps
 http://wiki.scratch.mit.edu/wiki/Glide_()_Secs_to_X:_()_Y:_()_(block)#Example_Uses
 http://wiki.scratch.mit.edu/wiki/Blocks#List_of_Blocks
 http://wiki.scratch.mit.edu/wiki/Glide_()_Secs_to_X:_()_Y:_()_(block)
 http://wiki.scratch.mit.edu/wiki/Creating_a_Quiz

You might also like