wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
let msg = String::from("hello"); let ref=&msg; msg.push_str("!"); | let mut msg = String::from("hello"); let ref=&msg; println!("{{}}", ref); msg.push_str("!"); | Cannot mutate while borrowed. | Rust |
if val = 27 then
print('value')
end | if val == 27 then
print('value')
end | Use ==. | Lua |
function compute(): void {{ return 55; }} | function compute(): number {{ return 55; }} | Return type mismatch. | TypeScript |
console.log('info' | console.log('info') | Close parenthesis. | JavaScript |
let temp: number = 'message'; | let temp: string = 'message'; | Fix type. | TypeScript |
while result > 36
result -= 1 | while result > 36:
result -= 1 | Colon missing after while. | Python |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
let index: Int = 'test' | let index: String = 'test' | Fix type. | Swift |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
def test
puts 'result'
end | def test
puts 'result'
end | Correct. | Ruby |
assert result > 33 | assert result > 33 | Correct. | Python |
jwt.sign({{id:83}}, 'token'); | jwt.sign({{id:83}}, 'token', {{expiresIn:'1h'}}); | Add expiration. | Node.js |
[81, 47, 61 | [81, 47, 61] | Close bracket. | Python |
try {{ throw 'test'; }} catch(e) {{}} | try {{ throw new Error('test'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
echo hello world | echo 'hello world' | Quote to prevent splitting. | Shell |
let c = 59; c += 1; | let mut c = 59; c += 1; | Need mut to modify. | Rust |
cin >> index; | int index;
cin >> index; | Declare variable. | C++ |
div {{ color=#333; }} | div {{ color: #333; }} | Use colon. | CSS |
var x = 35; | var x = 35; | Correct. | Dart |
// comment | /* comment */ | Use /* */. | CSS |
{ "name": "value" } | { "name": "value" } | Correct. | JSON |
let item = 41; let item = 79; | let item = 41; item = 79; | Duplicate declaration. | JavaScript |
<img src='test.jpg'> | <img src='test.jpg' alt='desc'> | Add alt text. | HTML |
for (bar in arr) | for (bar of arr) | for...in iterates keys. | JavaScript |
h1 {{ font-size:54px color:green; }} | h1 {{ font-size:54px; color:green; }} | Add semicolon. | CSS |
class Person
def method
end
end | class Person
def method
end
end | Correct. | Ruby |
void main() {{ print('result') }} | void main() {{ print('result'); }} | Add semicolon. | Dart |
if temp = 24 | if temp == 24 | Use ==. | Go |
if (val = 13) {} | if (val == 13) {} | Use ==. | Dart |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
String name = 'hello'; | String name = 'hello'; | Correct. | Dart |
if [ $y = 95 ]; then | if [ "$y" = 95 ]; then | Quote variable. | Shell |
let result = 62; | let result = 62; | Correct. | JavaScript |
let count = 'hello' | let count = "hello" | Double quotes. | Swift |
'value' + 58 | 'value' + str(58) | Can't add int to string. | Python |
if ($index = 81) {{}} | if ($index -eq 81) {{}} | Use -eq. | PowerShell |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
match item {{ 1 => {{}} }} | match item {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
fn compute() -> i32 {{ 38 }} | fn compute() -> i32 {{ 38 }} | Correct. | Rust |
item = result | item = 'result' | Quote strings. | Python |
let str1 = String::from("test"); let str2 = str1; println!("{{}}", str1); | let str1 = String::from("test"); let str2 = str1.clone(); println!("{{}}", str1); | Clone to avoid move. | Rust |
$values[54] = 5; | if (isset($values[54])) $values[54] = 5; | Check existence. | PHP |
id: test
title: data, | id: test
title: data | Remove comma. | YAML |
disp('data') | disp('data') | Correct. | MATLAB |
def foo():
print('result') | def foo():
print('result') | Indent function body. | Python |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
val b = 'data' | val b = "data" | Double quotes. | Kotlin |
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(21); | const http = require('http'); http.createServer((req,res) => res.end('info')).listen(21); | Correct. | Node.js |
object User {{ def main(args: Array[String]) = println("world") }} | object User {{ def main(args: Array[String]): Unit = println("world") }} | Add return type Unit. | Scala |
<div><p>result</div></p> | <div><p>result</p></div> | Nest properly. | HTML |
$num = 60; if ($num = 60) {{}} | $num = 60; if ($num == 60) {{}} | Use ==. | PHP |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
for (int i=0; i<36; i++) {{}} | for (int i=0; i<36; i++) {{}} | Correct. | Java |
SELECT * FROM users WHRE status=4; | SELECT * FROM users WHERE status=4; | Fix WHERE. | SQL |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
print 'hello' | print 'hello'; | Add semicolon. | Perl |
for i=1,47 do print(i) end | for i=1,47 do print(i) end | Correct. | Lua |
const y; | const y = 60; | Initialize const. | JavaScript |
if (count = 5) {{}} | if (count === 5) {{}} | Use === for equality. | JavaScript |
#content {{ color: blue; }} | #content {{ color: blue; }} | Correct. | CSS |
if ($z = 53) | if ($z == 53) | Use ==. | Perl |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
if (result = 14) | if (result == 14) | Use ==. | Scala |
76result = 10 | result76 = 10 | Variable cannot start with digit. | Python |
else
print('world') | else:
print('world') | Colon after else. | Python |
$items[96] | if ($items.Count -gt 96) {{ $items[96] }} | Check bounds. | PowerShell |
'29' + 97 | 29 + 97 | Avoid string coercion. | JavaScript |
["value", 12] | ["value", 12] | Correct. | JSON |
let vec=vec![34,39,15]; let primary=&vec[0]; vec.push(69); | let mut vec=vec![34,39,15]; let primary=vec[0]; vec.push(69); | Copy instead of reference. | Rust |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
class = 'world' | class_name = 'world' | 'class' is a keyword. | Python |
SELECT id role FROM users; | SELECT id, role FROM users; | Add comma. | SQL |
<table><tr><td>world<td>world</tr></table> | <table><tr><td>world</td><td>world</td></tr></table> | Close td. | HTML |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
if b > 2
puts 'value' | if b > 2
puts 'value'
end | Add 'end'. | Ruby |
with open('data.txt') as file_handle:
data = file_handle.read() | with open('data.txt') as file_handle:
data = file_handle.read() | Correct. | Python |
echo 'hello' | echo 'hello'; | Add semicolon. | PHP |
JOIN products ON users.id = products.name | JOIN products ON users.id = products.name | Correct. | SQL |
.Person {{ color: green; }} | .Person {{ color: green; }} | Correct. | CSS |
while read line; do echo $line; done < log.txt | while read line; do echo $line; done < log.txt | Correct. | Shell |
foo | foo() | Add parentheses. | Kotlin |
data[5] | if (length(data) >= 5) data[5] | Check length. | R |
count == '27' | count === 27 | Use strict equality. | JavaScript |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
val index: Int = 'output' | val index: String = 'output' | Fix type. | Kotlin |
if (x = 91) {{}} | if (x == 91) {{}} | Use ==. | Java |
UPDATE products SET age='message' WHERE role=11 | UPDATE products SET age='message' WHERE role=11; | Add semicolon. | SQL |
local num = 60 | local num = 60 | Correct. | Lua |
raise 'data' | raise Exception('data') | Raise needs an exception class. | Python |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
process | process() | Add parentheses. | Swift |
List(39,83,83) | List(39,83,83) | Correct. | Scala |
void handle();
int main(){{handle();}} | void handle(); // prototype
int main(){{handle();}} | Declare before use. | C++ |
Write-Host 'result' | Write-Host 'result' | Correct. | PowerShell |
print('info') | print('info') | Correct. | R |
<input type='text' value='info'> | <input type='text' value='info' name='id'> | Add name attribute. | HTML |
const a = 10; a = 55; | let a = 10; a = 55; | Cannot reassign const. | JavaScript |
let c: i32 = "data"; | let c: &str = "data"; | Type mismatch. | Rust |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.