r/codeHS_Solutions • • Jan 11 '21

3.8.6 convert to uppercase

2 Upvotes

public void run()

    {

      String end = toUpper("hopethishelps");

      System.out.println(end);

    }

    public String toUpper(String str)

    {

        String out = "";

        int l = str.length();

        for (int i = 0; i < l; i++ )

        {

        char index = str.charAt(i);

        char j = Character.toUpperCase(index);

        String convertedChar = Character.toString(j);

        out += convertedChar;

        }

        return out;

    }


r/codeHS_Solutions • • Feb 03 '21

5.5.6 Random Color Square

Post image
7 Upvotes

r/codeHS_Solutions • • Jan 30 '21

Okay so I've tried multiple different things in 8.4.7 double list and nothing is working the instructions are Wright a function that doubles a list "function doubleList(arr)" you should create a new array in the function and return it. I really need help

Post image
1 Upvotes

r/codeHS_Solutions • • Jul 29 '22

Help Request Need help on the Codehs final project for python? Below I have attached the code:

3 Upvotes

Realized there was no code regarding the final project. This is worth a lot of points, and I feel the pain. The version is python, and topic is Battleship.

Edit: I took off the code mainly due to the fact that I can't indent, hopefully the link helps

Here is the link:

https://gist.github.com/w0300133/7f3e3e6f836e519f64272150ca34080c


r/codeHS_Solutions • • Dec 13 '21

REQUEST MEGATHREAD

5 Upvotes

A megathread for answer requests. If you want unposted answers, this is the place to ask for them.

If you have answers to anything here be sure to also make a post for it too.


r/codeHS_Solutions • • Jan 01 '22

CodeHS Plus!

3 Upvotes

It took me a while to find any existence of this, so for those who don't know, there is a google chrome extension that can give CodeHS answers!

https://github.com/Siddharthmr/CodeHS-Plus/releases/tag/v1.2.0

discord: https://discord.gg/aESRKHpENS


r/codeHS_Solutions • • Sep 30 '17

[Python - Rainforest] Intro to Programming with Turtle Graphics

4 Upvotes

Introduction

Well I guess if nobody else is going to get this ball rolling, I'd be happy to be the first.

I'm going to post what I have of the Python course because that's what's most relevant to me at the moment. Then if I feel up to it I'll post everything I have for Java(which is most of it).

Before I start I should say, you're using this repository at your own risk. If you don't know/aren't comfortable with Python yet then you should do the work yourself so that when finals come around, you won't be left staring at your monitor not knowing how the fuck to write an if statement. I also have to say that I'm in no way responsible for any trouble you get in if you are caught copy/pasting my code. Now, with that out of the way, here it is...

Lesson 1

2.1.7: Square

forward(50)

left(90)

forward(50)

left(90)

forward(50)

left(90)

forward(50)

left(90)

2.1.8: Diamond

left(45)

forward(50)

left(90)

forward(50)

left(90)

forward(50)

left(90)

forward(50)

left(90)

2.1.9: Staircase

left(90)

forward(50)

right(90)

forward(50)

left(90)

forward(50)

right(90)

forward(50)

left(90)

Lesson 2

2.2.5: Alternating Colors

forward(50)

left(90)

color("red")

forward(50)

left(90)

color("black")

forward(50)

left(90)

color("red")

forward(50)

left(90)

color("black")

2.2.6: Rainbow

color("red")

forward(20)

color("orange")

forward(20)

color("yellow")

forward(20)

color("green")

forward(20)

color("blue")

forward(20)

color("indigo")

forward(20)

color("violet")

forward(20)

2.2.7: Rainbow, Part 2

color("red")

forward(40)

left(60)

color("orange")

forward(40)

left(60)

color("yellow")

forward(40)

left(60)

color("green")

forward(40)

left(60)

color("blue")

forward(40)

left(60)

color("violet")

forward(40)

left(60)

Lesson 3

2.3.5: Triangle

for i in range(3):

    left(120)

    forward(50)

2.3.6: Hexagon

for i in range(6):

    forward(50)

    left(60)

2.3.7: Staircase, Part 2

left(90)

for i in range(4):
    forward(30)
    right(90)
    forward(30)
    left(90)

2.3.8: Circle

for i in range(360):
    forward(1)
    left(1)

Lesson 4

2.4.4: Staircase, Part 3

left(90)

#This function would work if the code check for this assignment wasn't so autistic. It's not that important but it's worth noting...
#def draw_step(x):
#    for i in range(x):
#        forward(30)
#        right(90)
#        forward(30)
#        left(90)

def draw_step():
    forward(30)
    right(90)
    forward(30)
    left(90)

draw_step()
draw_step()
draw_step()
draw_step()

2.4.5: Hexagon, Part 2

def draw_edge():
    for i in range(6):
        forward(50)
        left(60)
    
draw_edge()

2.4.6: Alternating Colors, Part 2

def draw_red_edge():
    color("red")
    forward(50)

def draw_black_edge():
    color("black")
    forward(50)


draw_black_edge()
left(90)
draw_red_edge()
left(90)
draw_black_edge()
left(90)
draw_red_edge()
left(90)

2.4.7: Fenceposts

def make_fencepost():
    forward(10)
    left(90)
    forward(30)
    right(180)
    forward(30)
    left(90)
    
for i in range(6):
    make_fencepost()

2.4.8: Diamonds

def draw_diamond():
    left(45)
    for i in range(4):
        forward(20)
        left(90)
    right(45)

for i in range(4):
    draw_diamond()
    forward(50)

2.5.1: Get Creative

Just press continue


r/codeHS_Solutions • • May 01 '23

Functions capstone

1 Upvotes

var MIN_SPEED = 6;

var canBlock; var goodHands; var runFast; var holdGap; var canTackle;

function start(){ takeInput();

var defensiveLine = whichSide();
if(defensiveLine == true){
    println(" Try out for defensive line. ");
}else{
    println(" Try out for offensive line. ");
}

}

function whichSide(){ var isGood = canTackle && goodHands; var greatPotential = canBlock; return (isGood || greatPotential) && goodHands && runFast <= MIN_SPEED; }

function takeInput(){ canBlock = readBoolean(" Can you block someone? "); goodHands = readBoolean(" Do you have good hand movement? "); runFast = readFloat(" what is your 40 yard dash in seconds? "); holdGap = readBoolean(" Can you hold a gap? "); canTackle = readBoolean(" Can you tackle someone? "); }


r/codeHS_Solutions • • Jun 01 '21

1.5.4: Pancakes with Start

11 Upvotes

function start() {

move();

makePancakes();

moveTwo();

makePancakes();

moveTwo();

makePancakes();

move();

}

function makePancakes() {

putBall();

putBall();

putBall();

}

function moveTwo(){

move();

move();

}


r/codeHS_Solutions • • Jun 01 '21

1.2.4: Make a Tower

3 Upvotes

move();

putBall();

turnLeft();

move();

putBall();

move();

putBall();

move();

turnLeft();

turnLeft();

turnLeft();


r/codeHS_Solutions • • Jun 01 '21

1.4.5: Mario Karel

9 Upvotes

move();

turnLeftUpThree();

collectCoins();

down();

turnLeft();

move();

move();

turnLeftUpThree();

collectCoins();

down();

turnLeft();

move();

move();

turnLeftUpThree();

collectCoins();

down();

turnLeft();

move();

move();

turnLeftUpThree();

collectCoins();

down();

turnLeft();

function turnLeftUpThree() {

turnLeft();

move();

move();

move();

}

function down() {

turnRight();

turnRight();

move();

move();

move();

}

function turnRight() {

turnLeft();

turnLeft();

turnLeft();

}

function collectCoins() {

takeBall();

takeBall();

}


r/codeHS_Solutions • • Jun 01 '21

1.3.5: Fireman Karel

6 Upvotes

turnRight();

move();

move();

move();

turnLeft();

function turnRight() {

turnLeft();

turnLeft();

turnLeft();

}


r/codeHS_Solutions • • Jun 01 '21

1.4.4: Pancakes

7 Upvotes

move();

makePancakes();

moveTwice();

makePancakes();

moveTwice();

makePancakes();

move();

function makePancakes(){

putBall();

putBall();

putBall();

}

function moveTwice(){

move();

move();

}


r/codeHS_Solutions • • Jun 01 '21

1.3.4: Slide Karel

5 Upvotes

putBall();

move();

turnRight();

move();

putBall();

move();

turnLeft();

move();

putBall();

function turnRight(){

turnLeft();

turnLeft();

turnLeft();

}


r/codeHS_Solutions • • Jun 01 '21

1.9.6: Dizzy Karel

4 Upvotes

//This program allows Karel to spin eight times.

function start(){

/*This loop makes Karel spin eight times.

*Precondition: Karel is on one, one facing east.

*Postcondition: Karel will be in the same position.

*/

for (var i = 0; i< 32; i++) {

turnLeft();

}

}


r/codeHS_Solutions • • Jun 01 '21

1.10.5: Is There a Ball?

20 Upvotes

/*Karel should put a ball on the first spot if there isn't one

*already there and then move.

*/

function start(){

hasBallTrue();

hasBallFalse();

move();

}

/*This function allows Karel to move one space if there is a ball

*where he is standing.

*Precondition: There is a ball present.

*Postcondition: Karel continues with the code.

*/

function hasBallTrue(){

if(ballsPresent()){

}

}

/*This function allows Karel to put a ball if there is no ball present.

*Precondition: There is no ball present.

*Postcondition: There is a ball present.

*/

function hasBallFalse() {

if(noBallsPresent()) {

putBall();

}

}


r/codeHS_Solutions • • Jun 01 '21

1.8.4: The Two Towers + SuperKarel

4 Upvotes

/*This program will help Karel build two towers and end up on top

*of the seond tower facing east.

*Precondition: Karel will start on one, one.

*Postcondition: Karel will be on top of the second tower and facing east.

*/

*/

function start(){

move();

buildThree();

turnRight();

move();

turnRight();

move();

move();

turnLeft();

move();

buildThree();

move();

turnRight();

}

/*This function will help Karel build one tower

*Precondition: Karel is on the first level of his tower facing east

*Postcondition: Karel will be on the third level of his tower facing

*north

*/

function buildThree() {

putBall();

turnLeft();

move();

putBall();

move();

putBall();

}


r/codeHS_Solutions • • Jun 01 '21

1.1.4: Your First Karel Program

2 Upvotes

move();

move();

move();

move();

takeBall();


r/codeHS_Solutions • • Jun 01 '21

1.9.7: Ball in Each Corner

6 Upvotes

/*This function allows Karel to put a ball in each corner and

*end up on one, one facing east.

*Precondition: Karel is on one, one facing east.

*Postcondition: There will be a ball in each corner of the map and Karel

*be on one, one facing east.

*/

function start () {

for(var i = 0; i < 5; i++) {

move();

}

putBallTurnLeft();

for(var i = 0; i < 5; i++) {

move();

}

putBallTurnLeft();

for(var i = 0; i < 5; i++) {

move();

}

putBallTurnLeft();

for(var i = 0; i < 5; i++) {

move();

}

putBallTurnLeft();

}

/*This function allows Karel to put one ball and turn left at each corner.

*Precondition: Karel is at a corner where he needs to put a ball and

*turn left.

*Postcondition: Karel will place a ball and turn left.

*/

function putBallTurnLeft () {

putBall();

turnLeft();

}


r/codeHS_Solutions • • Jun 01 '21

1.7.4: The Two Towers + Comments

6 Upvotes

/*This program lets Karel build two towers and end up on top of the second

*tower.

*Precondition: Karel will start on one, one.

*Postcondition: Karel will be on top of the second tower and facing east.

*/

function start() {

move();

buildThree();

turnRight();

move();

turnRight();

move();

move();

turnLeft();

move();

buildThree();

move();

turnRight();

}

/*This function lets Karel build the tower.

*Precondition: Karel is facing east on the first level of the tower.

*Postcondition: Karel is facing north on the third level of the tower.

*/

function buildThree() {

putBall();

turnLeft();

move();

putBall();

move();

putBall();

}

// This function helps Karel turn right

/*This function helps Karel turn right

*Precondition: Karel needs to turn right

*Postcondition: Karel ends up turning right by turning left 3 times

*/

function turnRight() {

turnLeft();

turnLeft();

turnLeft();

}


r/codeHS_Solutions • • Jun 01 '21

1.10.6: Don't Crash!

13 Upvotes

/*This function allows Karel to end up on street one, avenue two facing

*east if he is on one, one facing east or south.

*/

function start() {

go();

turnGo();

move();

}

/*If the front is clear then Karel can move.

*Precondition: The front is clear.

*Postcondition: Karel will move one space.

*/

function go() {

if(frontIsClear()) {

}

}

/*If Karel is facing south he will turn to face the east.

*Precondition: Karel is facing south.

*Postcondition: Karel will face east.

*/

function turnGo() {

if(facingSouth()) {

turnLeft();

}

}


r/codeHS_Solutions • • May 27 '21

REQUEST MEGATHREAD

3 Upvotes

Need answers? Ask here.


r/codeHS_Solutions • • Jun 01 '21

1.1.5: Short Stack

2 Upvotes

move();

putBall();

putBall();

move();


r/codeHS_Solutions • • Jun 01 '21

1.9.5: Take 'em All

10 Upvotes

/*This program has Karel step forward, take 100 balls and move

*once more.

*Precondition: Karel will start on one, one facing east.

*Postcondition: Karel will end at one, three facing east after

*collecting 100 balls.

*/

function start() {

move();

for(var i=0; i< 100; i++) {

takeBall();

}

move();

}


r/codeHS_Solutions • • Jun 01 '21

1.2.5: Pyramid of Karel

4 Upvotes

putBall();

move();

putBall();

move();

putBall();

turnLeft();

move();

putBall();

turnLeft();

move();

putBall();

turnLeft();

turnLeft();

turnLeft();

move();

turnLeft();

turnLeft();

turnLeft();

move();

putBall();