Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ====JS Control Stuctures 6.6.4-6.8.4====
- ==6.6.4==
- function start(){
- var line = ["Sam", "Lisa", "Laurie", "Bob", "Ryan"];
- var line2 = ["Tony", "Lisa", "Laurie", "Karen"];
- if(line.indexOf("Bob") != -1) {println("Bob is in the first line.");}
- else{println("Bob is not in the first line.");}
- if(line2.indexOf("Bob") != -1) {println("Bob is in the second line.");}
- else{println("Bob is not in the second line.");}
- // Your code goes here
- }
- ==6.7.4==
- function start(){
- var line = ["Sam", "Lisa", "Laurie", "Bob", "Ryan"];
- // Your code goes here
- println(line[0] + ", " + line[1] + ", " + line[2] + ", " +line[3] + ", " +line[4]);
- line.remove("Sam");
- line.remove("Lisa");
- println(line[0] + ", " + line[1] + ", " + line[2]);
- }
- ==6.8.4==
- function start() {
- // Create your coin flip simulation here
- var i = 0;
- while(i < 100) {
- if(Randomizer.nextBoolean()) {println("Heads");}
- else {println("Tails");}
- i++;
- }
- }
- ====Digital Information====
- ==7.3.7==
- 01001000
- 01100101
- 01101100
- 01101100
- 01101111
- 00101100
- 00100000
- 01001011
- 01100001
- 01110010
- 01100101
- 01101100
- 00100001
- ==7.4.5==
- 01010101 10101010 01010101 10101010 01010101 10101010 01010101 10101010
- ==7.4.6==
- 01110
- 01110
- 00000
- 01110
- 01110
- 00000
- 01110
- 01110
- 00000
- 01110
- 01110
- 00000
- 01110
- 01110
- 00000
- 01110
- 01110
- 00000
- 01110
- 01110
- ==7.4.7==
- 234234e2139649283764862497
- ==7.6.6==
- FF0000
- 00FF00
- 0000FF
- ==7.6.7==
- FF0000
- 00FF00
- 0000FF
- FFFF00
- ==7.6.8==
- FF0000
- FF7700
- FFFF00
- 00FF00
- 0000FF
- FF00FF
- ==7.6.9==
- 79427549579475923759749579347593459294583458345843503450450ffdffff008508508f87f89d709f7d9f79427549579475923759749579347593459294583458345843503450450ffdffff008508508f87f89d709f7d9f79427549579475923759749579347593459294583458345843503450450ffdffff008508508f87f89d709f7d9f79427549579475923759749579347593459294583458345843503450450ffdffff008508508f87f89d709f7d9f79427549579475923759749579347593459294583458345843503450450ffdffff008508508f87f89d709f7d9f79427549579475923759749579347593459294583458345843503450450ffdffff008508508f87f89d709f7d9f79427549579475923759749579347593459294583458345843503450450ffdffff008508508f87f89d709f7d9f
- ==7.7.9==
- // Constants for the image
- var IMAGE_URL = "https://codehs.com/static/img/zebra.jpg";
- var IMAGE_WIDTH = 350;
- var IMAGE_HEIGHT = 250;
- var IMAGE_X = getWidth() / 2 - IMAGE_WIDTH / 2;
- var IMAGE_Y = getHeight() / 2 - IMAGE_HEIGHT / 2;
- // Constants for the pixel array
- var RED = 0;
- var GREEN = 1;
- var BLUE = 2;
- // Constants for the pixel filter
- var MAX_COLOR_VALUE = 255;
- // We need to wait for the image to load before modifying it
- var IMAGE_LOAD_WAIT_TIME = 50;
- /*
- * Given a pixel array with 3 values [R, G, B]
- * Modifies the pixel array such that each value is inverted ie:
- * R = 255 - R
- * G = 255 - G
- * B = 255 - B
- * Returns the modified pixel array
- */
- function invertPixel(pixel) {
- // WRITE THIS FUNCTION
- var red = pixel[0];
- var green = pixel[1];
- var blue = pixel[2];
- red = 255-red;
- blue = 255-blue;
- green = 255-green;
- var newPixel = [red,green,blue];
- return newPixel;
- }
- // Inverts the colors of each pixel in the WebImage image
- function invert(image) {
- for(var x = 0; x < image.getWidth(); x++) {
- for (var y = 0; y < image.getHeight(); y++) {
- // Get the current pixel
- var pixel = image.getPixel(x, y);
- // Modify the current pixel
- pixel = invertPixel(pixel);
- // Update the image with the modified pixel
- image.setRed(x, y, pixel[RED]);
- image.setGreen(x, y, pixel[GREEN]);
- image.setBlue(x, y, pixel[BLUE]);
- }
- }
- }
- function start() {
- // Set up the image
- var image = new WebImage(IMAGE_URL);
- image.setSize(IMAGE_WIDTH, IMAGE_HEIGHT);
- image.setPosition(IMAGE_X, IMAGE_Y);
- // Add it to the canvas
- add(image);
- // Wait for it to load before applying the filter
- setTimeout(function(){
- invert(image);
- }, IMAGE_LOAD_WAIT_TIME);
- }
- ==7.7.10==
- // Constants for the image
- var IMAGE_URL = "https://codehs.com/static/img/zebra.jpg";
- var IMAGE_WIDTH = 350;
- var IMAGE_HEIGHT = 250;
- var IMAGE_X = getWidth() / 2 - IMAGE_WIDTH / 2;
- var IMAGE_Y = getHeight() / 2 - IMAGE_HEIGHT / 2;
- // We need to wait for the image to load before modifying it
- var IMAGE_LOAD_WAIT_TIME = 50;
- // Filter that sets the blue value of every pixel in the image to be 0
- function removeBlue(image) {
- for (var x = 0; x < image.getWidth();x++) {
- for (var y = 0; y < image.getHeight();y++) {
- var pixel = getPixel(x,y);
- pixel[2] = 0;
- setPixel(x,y,pixel);
- }
- }
- }
- function start() {
- // Set up the image
- var image = new WebImage(IMAGE_URL);
- image.setSize(IMAGE_WIDTH, IMAGE_HEIGHT);
- image.setPosition(IMAGE_X, IMAGE_Y);
- // Add it to the canvas
- add(image);
- // Wait for it to load before applying the filter
- setTimeout(function(){
- removeBlue(image);
- }, IMAGE_LOAD_WAIT_TIME);
- }
- ==7.7.11==
- // Constants for the image
- var IMAGE_URL = "https://codehs.com/static/img/about/goldengate.jpg";
- var IMAGE_WIDTH = 350;
- var IMAGE_HEIGHT = 250;
- var IMAGE_X = getWidth() / 2 - IMAGE_WIDTH / 2;
- var IMAGE_Y = getHeight() / 2 - IMAGE_HEIGHT / 2;
- // Constants for the filter
- var DARKENING_FACTOR = 25;
- var MIN_PIXEL_VALUE = 0;
- // Constants for pixel indices
- var RED = 0;
- var GREEN = 1;
- var BLUE = 2;
- // We need to wait for the image to load before modifying it
- var IMAGE_LOAD_WAIT_TIME = 50;
- // Filter that takes an image as a parameter
- // and darkens the pixels in the left half of the image
- function darkenFilter(image) {
- for (var x = 0; x < image.getWidth();x++) {
- for (var y = 0; y < image.getHeight();y++) {
- var pixel = image.getPixel(x,y);
- pixel[0] = pixel[0] - DARKENING_FACTOR;
- pixel[1] = pixel[1] - DARKENING_FACTOR;
- pixel[2] = pixel[2] - DARKENING_FACTOR;
- image.setPixel(x,y,pixel);
- }
- }
- }
- function start() {
- // Set up the image
- var image = new WebImage(IMAGE_URL);
- image.setSize(IMAGE_WIDTH, IMAGE_HEIGHT);
- image.setPosition(IMAGE_X, IMAGE_Y);
- // Add it to the canvas
- add(image);
- // Wait for it to load before applying the filter
- setTimeout(function(){
- darkenFilter(image);
- }, IMAGE_LOAD_WAIT_TIME);
- }
- ==7.9.4==
- 0000000000001111110001011110100110110110011100111001110011100110110110010111101000111111000000000000
- ==7.10.8==
- /*
- * Write a program that guesses every possible 4 digit passcode
- * combinations until the correct passcode is guessed.
- *
- * The passcode is randomly generated and stored in the variable
- * secretPasscode.
- *
- * Print out how many guesses it took to guess the correct passcode.
- */
- function start() {
- var secretPasscode = generateRandomPasscode();
- for (var guessInt = 0; guessInt < 1000; guessInt++) {
- let guess = pad(`${guessInt}`,4);
- if(guess === secretPasscode){
- println(`we just started counting, and found the passcode at ${guessInt} `);
- break;
- }
- }
- }
- function pad(str, length) {
- while (str.length < length) str = '0' + str;
- return str;
- }
- // Checks whether the given guess passcode is the correct passcode
- function isCorrect(guessCode, correctCode) {
- return guessCode == correctCode;
- }
- // Generates a random 4 digit passcode and returns it as a String
- function generateRandomPasscode() {
- var randomPasscode = "";
- for(var i = 0; i < 4; i++) {
- var randomDigit = Randomizer.nextInt(0, 9);
- randomPasscode += randomDigit;
- }
- return randomPasscode;
- }
- ==7.13.2==
- // DESCRIBE YOUR FILTER HERE IN THIS COMMENT!
- function customFilter(image) {
- for (var x = 0; x < image.getWidth();x++) {
- for (var y = 0; y < image.getHeight();y++) {
- var pixel = getPixel(x,y);
- pixel[0] = 0;
- pixel[1] = Math.random();
- pixel[2] = 128;
- setPixel(x,y,pixel);
- }
- }
- }
- // WRITE ANY HELPER FUNCTIONS HERE
- /*********************************************
- * You do not need to write any code below this line.
- * This is starter code that sets up the image on the screen
- * and calls your customFilter function.
- * Feel free to read this code and learn how it works!
- * Be careful though, if you modify this code the program may not
- * work correctly.
- *********************************************/
- // Constants for the image
- var IMAGE_URL = "https://codehs.com/static/img/zebra.jpg";
- var IMAGE_WIDTH = 350;
- var IMAGE_HEIGHT = 250;
- var IMAGE_X = getWidth() / 2 - IMAGE_WIDTH / 2;
- var IMAGE_Y = getHeight() / 2 - IMAGE_HEIGHT / 2;
- // We need to wait for the image to load before modifying it
- var IMAGE_LOAD_WAIT_TIME = 50;
- function start() {
- // Set up the image
- var image = new WebImage(IMAGE_URL);
- image.setSize(IMAGE_WIDTH, IMAGE_HEIGHT);
- image.setPosition(IMAGE_X, IMAGE_Y);
- // Add it to the canvas
- add(image);
- // Wait for it to load before applying the filter
- setTimeout(function(){
- customFilter(image);
- }, IMAGE_LOAD_WAIT_TIME);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement